Future: Reschedule onTimeout/orElse if not yet expired

This commit is contained in:
Derek Williams 2011-08-06 14:10:36 -06:00
parent bc1f7565b7
commit 0ae7a72f3a

View file

@ -816,7 +816,14 @@ class DefaultPromise[T](val timeout: Timeout)(implicit val dispatcher: MessageDi
if (!timeout.duration.isFinite) false //Not possible
else if (value.isEmpty) {
if (!isExpired) {
val runnable = new Runnable { def run() { if (!isCompleted) func(DefaultPromise.this) } } //TODO Reschedule is run prematurely
val runnable = new Runnable {
def run() {
if (!isCompleted) {
if (!isExpired) Scheduler.scheduleOnce(this, timeLeft, NANOS)
else func(DefaultPromise.this)
}
}
}
Scheduler.scheduleOnce(runnable, timeLeft, NANOS)
false
} else true
@ -837,7 +844,10 @@ class DefaultPromise[T](val timeout: Timeout)(implicit val dispatcher: MessageDi
promise completeWith this
val runnable = new Runnable {
def run() {
if (!isCompleted) promise complete (try { Right(fallback) } catch { case e: Exception Left(e) })
if (!isCompleted) {
if (!isExpired) Scheduler.scheduleOnce(this, timeLeft, NANOS)
else promise complete (try { Right(fallback) } catch { case e: Exception Left(e) })
}
}
}
Scheduler.scheduleOnce(runnable, timeLeft, NANOS)