|
Play Framework/Scala example source code file (PromiseSpec.scala)
The PromiseSpec.scala Play Framework example source code/* * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> */ package play.it.concurrent import play.api.test._ import scala.concurrent.ExecutionContext.Implicits.global import play.api.libs.concurrent.Promise class PromiseSpec extends PlaySpecification { "Promise" can { "Redeemed values" in new WithApplication() { val p = Promise.timeout(42, 100) await(p.filter(_ == 42)) must equalTo (42) } "Redeemed values not matching the predicate" in new WithApplication() { val p = Promise.timeout(42, 100) await(p.filter(_ != 42)) must throwA [NoSuchElementException] } "Thrown values" in new WithApplication() { val p = Promise.timeout(42, 100).map[Int]{ _ => throw new Exception("foo") } await(p.filter(_ => true)) must throwAn [Exception](message = "foo") } } "Promise timeouts" should { "yield their message" in new WithApplication() { val future = Promise.timeout("hello", 10) await(future) must_== "hello" } "yield any exceptions thrown when generating a message" in new WithApplication() { val future = Promise.timeout[Unit](throw new Exception("error!"), 10) await(future) must throwAn[Exception](message = "error!") } } } Other Play Framework source code examplesHere is a short list of links related to this Play Framework PromiseSpec.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.