Created
November 13, 2015 22:47
-
-
Save sam/768d3eac7bfad75777a9 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
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) | |
} |
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
val firstLove = Future { | |
Thread.sleep(500) | |
"i love you" | |
} | |
val thenBetray = firstLove map { loveLetter => | |
println(loveLetter) | |
Thread.sleep(500) | |
"not really" | |
} | |
thenBetray foreach println |
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
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)) | |
} |
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
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