Skip to content

Instantly share code, notes, and snippets.

@olix0r
Created February 19, 2016 19:26
Show Gist options
  • Save olix0r/6105d0129545a4d5ce36 to your computer and use it in GitHub Desktop.
Save olix0r/6105d0129545a4d5ce36 to your computer and use it in GitHub Desktop.
Is this safe?
def call(): Future[String] = ???
val strings = Var.async[Try[String]](None) { strings =>
def loop(): Future[Unit] =
call().transform {
case Return(s) =>
strings() = Return(s)
Future.sleep(1.minute).before(loop())
case Throw(NonFatal(e)) =>
strings() = Throw(e)
Future.sleep(1.minute).before(loop())
case Throw(e) =>
strings() = Throw(e)
}
val working = loop()
Closable.make { deadline =>
working.raise(Cancelled)
Future.Unit
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment