Skip to content

Instantly share code, notes, and snippets.

@sam
Created November 13, 2015 22:47
Show Gist options
  • Save sam/768d3eac7bfad75777a9 to your computer and use it in GitHub Desktop.
Save sam/768d3eac7bfad75777a9 to your computer and use it in GitHub Desktop.
val firstLove = future {
Thread.sleep(500)
"i love you"
}
val thenBetray = firstLove map {
case loveLetter => {
Console.println(loveLetter)
Thread.sleep(500)
"not really"
}
}
thenBetray onSuccess {
case partingWords => Console.println(partingWords)
}
val firstLove = Future {
Thread.sleep(500)
"i love you"
}
val thenBetray = firstLove map { loveLetter =>
println(loveLetter)
Thread.sleep(500)
"not really"
}
thenBetray foreach println
async {
val firstLove = Future {
Thread.sleep(500)
"i love you"
}
val loveLetter = await(firstLove)
println(loveLetter)
val thenBetray = {
Thread.sleep(500)
"not really"
}
println(await(thenBetray))
}
for {
loveLetter <- Future {
Thread.sleep(500)
"i love you"
}
thenBetray <- Future {
println(loveLetter)
Thread.sleep(500)
"not really"
}
} println(thenBetray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment