Skip to content

Instantly share code, notes, and snippets.

@debasishg
Last active December 20, 2015 03:39
Show Gist options
  • Select an option

  • Save debasishg/6065313 to your computer and use it in GitHub Desktop.

Select an option

Save debasishg/6065313 to your computer and use it in GitHub Desktop.
@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