Created
May 5, 2016 04:58
-
-
Save olix0r/22257b1234354eea2a567495e9826798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* check a condition asynchronously until it's true and then do another thing | |
*/ | |
def checkCond: Future[Boolean] = ??? | |
def doThing[T]: Future[T] = ??? | |
implicit val timer = DefaultTimer.twitter | |
def untilCondition(backoff: Stream[Duration]): Future[Unit] = | |
checkCond.flatMap { | |
case false => | |
backoff match { | |
case wait #:: backoff => | |
Future.sleep(wait).before(untilCondition(backoff)) | |
case _ => Future.exception(new Exception("I fucked up")) | |
} | |
case true => Future.Unit | |
} | |
val thing: Future[T] = untilCondition(Backoff.exponentialJittered(0.millis, 1.minute)).before(doThing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment