Last active
December 20, 2015 03:39
-
-
Save debasishg/6065313 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @volatile var callbackExecuted = false | |
| val ks = (1 to 10).map(i => s"client_key_$i") | |
| val kvs = ks.zip(1 to 10) | |
| val sets: Seq[Future[Boolean]] = kvs map { | |
| case (k, v) => client.set(k, v) | |
| } | |
| val setResult = Future.sequence(sets) map { r: Seq[Boolean] => | |
| callbackExecuted = true | |
| r | |
| } | |
| callbackExecuted should be (false) | |
| setResult.futureValue should contain only (true) | |
| callbackExecuted should be (true) | |
| callbackExecuted = false | |
| val gets: Seq[Future[Option[Long]]] = ks.map { k => client.get[Long](k) } | |
| val getResult = Future.sequence(gets).map { rs => | |
| callbackExecuted = true | |
| rs.flatten.sum | |
| } | |
| callbackExecuted should be (false) | |
| getResult.futureValue should equal (55) | |
| callbackExecuted should be (true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment