You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is that a solution that tries to short circuit becomes a bit race conditiony and how failures are propagated becomes unclear.
Sample solution, if there is a failure in both fa and fb, which is used?
/** * @return A new future that will complete with false as soon as either future completes with false * or true when both futures has completed and are true.*/deffirstAnd(fa: Future[Boolean], fb: Future[Boolean])(implicitec: ExecutionContext) = {
valpromise=Promise[Boolean]()
fa.onComplete {
caseSuccess(false) => promise.trySuccess(false)
caseFailure(ex) => promise.tryFailure(ex)
}
fb.onComplete {
caseSuccess(false) => promise.trySuccess(false)
caseFailure(ex) => promise.tryFailure(ex)
}
fa.zip(fb).onComplete {
// this is the only case that can happen after the abovecaseSuccess((true, true)) => promise.trySuccess(true)
}
promise.future
}
Consider these cases:
We could make them resolve as fast as the fastest future, in best case.
The text was updated successfully, but these errors were encountered: