Created
March 30, 2013 13:26
-
-
Save msulima/5276672 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 concurrent.duration._ | |
import concurrent.{Await, Future, Promise} | |
import org.scalatest.FunSuite | |
import scala.concurrent.ExecutionContext.Implicits.global | |
class Snippets extends FunSuite { | |
test("Promise can be fulfilled") { | |
val numberPromise = Promise[Int]() | |
val addedFuture = addThree(numberPromise.future) | |
assert(addedFuture.isCompleted == false) | |
numberPromise.success(7) | |
val added = Await.result(addedFuture, 1 seconds) | |
assert(added == 10) | |
} | |
def addThree(value: Future[Int]): Future[Int] = | |
value.map(a => a + 3) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment