Skip to content

Instantly share code, notes, and snippets.

@msulima
Created March 30, 2013 13:26
Show Gist options
  • Save msulima/5276672 to your computer and use it in GitHub Desktop.
Save msulima/5276672 to your computer and use it in GitHub Desktop.
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