Created
July 21, 2015 20:29
-
-
Save brianwawok/98a231396fc87675fba3 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
import org.joda.time.DateTime | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.{Await, ExecutionContext, Future} | |
import scala.concurrent.duration._ | |
object FooBar { | |
def slowThing(number: Int)(implicit ec: ExecutionContext): Future[Unit] = { | |
println(s"${new DateTime().toString()}: Pre future for $number ") | |
val res = Future { | |
println(s"${new DateTime().toString()}: Start of future for $number ") | |
Thread.sleep(10 * 1000) | |
println(s"${new DateTime().toString()}: End of future for $number ") | |
} | |
println(s"${new DateTime().toString()}: Post future for $number ") | |
res | |
} | |
def main(args: Array[String]): Unit = { | |
val agg = for (u1 <- slowThing(1); | |
u2 <- slowThing(2)) yield (u1, u2) | |
println("Waiting for 25") | |
Thread.sleep(25 * 1000) | |
println("Done waiting") | |
} | |
2015-07-21T16:28:10.078-04:00: Pre future for 1 | |
2015-07-21T16:28:10.168-04:00: Post future for 1 | |
2015-07-21T16:28:10.168-04:00: Start of future for 1 | |
Waiting for 25 | |
2015-07-21T16:28:20.169-04:00: End of future for 1 | |
2015-07-21T16:28:20.169-04:00: Pre future for 2 | |
2015-07-21T16:28:20.169-04:00: Post future for 2 | |
2015-07-21T16:28:20.170-04:00: Start of future for 2 | |
2015-07-21T16:28:30.170-04:00: End of future for 2 | |
2015-07-21T16:28:30.170-04:00: All Done!!!! | |
Done waiting | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment