Skip to content

Instantly share code, notes, and snippets.

@JohnMurray
Last active January 16, 2018 21:41
Show Gist options
  • Save JohnMurray/85072a9133733a8397126fa354ea68f2 to your computer and use it in GitHub Desktop.
Save JohnMurray/85072a9133733a8397126fa354ea68f2 to your computer and use it in GitHub Desktop.
A proper way to make a Future-wait (sleep) with Akka
import akka.actor.ActorSystem
import akka.pattern.Patterns.after
import scala.concurrent.duration._
val as = ActorSystem()
val x = after(2.seconds, as.scheduler, global, Future.successful(1)).flatMap { _ =>
Future {
// long operation that _starts_ after the delayed future completes
1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment