summaryrefslogtreecommitdiff
path: root/src/library/scala/concurrent/ExecutionContext.scala
diff options
context:
space:
mode:
authoraleksandar <aleksandar@lampmac14.epfl.ch>2012-01-19 20:33:01 +0100
committeraleksandar <aleksandar@lampmac14.epfl.ch>2012-01-19 20:33:01 +0100
commitf58ade23be8354aab223da5ca1e7162b6b53749b (patch)
tree79c00ef6a9b8af62aae6f4fde0b9b3e68d31d796 /src/library/scala/concurrent/ExecutionContext.scala
parent778e7d1a1b87431449cbe7335ca3a66fbe7c8366 (diff)
downloadscala-f58ade23be8354aab223da5ca1e7162b6b53749b.tar.gz
scala-f58ade23be8354aab223da5ca1e7162b6b53749b.tar.bz2
scala-f58ade23be8354aab223da5ca1e7162b6b53749b.zip
Add NonDeterministic evidence needed to call nondeterministic methods.
Diffstat (limited to 'src/library/scala/concurrent/ExecutionContext.scala')
-rw-r--r--src/library/scala/concurrent/ExecutionContext.scala20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/library/scala/concurrent/ExecutionContext.scala b/src/library/scala/concurrent/ExecutionContext.scala
index 0657121de2..260d4cb54d 100644
--- a/src/library/scala/concurrent/ExecutionContext.scala
+++ b/src/library/scala/concurrent/ExecutionContext.scala
@@ -16,6 +16,7 @@ import scala.util.Duration
import scala.concurrent.forkjoin.{ ForkJoinPool, RecursiveTask => FJTask, RecursiveAction, ForkJoinWorkerThread }
import scala.collection.generic.CanBuildFrom
import collection._
+import annotation.implicitNotFound
@@ -41,10 +42,21 @@ trait ExecutionContext {
private implicit val executionContext = this
+ def keptPromise[T](result: T): Promise[T] = {
+ val p = promise[T]
+ p success result
+ }
+
+ def brokenPromise[T](t: Throwable): Promise[T] = {
+ val p = promise[T]
+ p failure t
+ }
+
/** TODO some docs
*
*/
def all[T, Coll[X] <: Traversable[X]](futures: Coll[Future[T]])(implicit cbf: CanBuildFrom[Coll[_], T, Coll[T]]): Future[Coll[T]] = {
+ import nondeterministic._
val buffer = new mutable.ArrayBuffer[T]
val counter = new AtomicInteger(1) // how else could we do this?
val p: Promise[Coll[T]] = promise[Coll[T]] // we need an implicit execctx in the signature
@@ -78,7 +90,8 @@ trait ExecutionContext {
/** TODO some docs
*
*/
- def any[T](futures: Traversable[Future[T]]): Future[T] = {
+ @implicitNotFound(msg = "Calling this method yields non-deterministic programs.")
+ def any[T](futures: Traversable[Future[T]])(implicit nondet: NonDeterministic): Future[T] = {
val p = promise[T]
val completeFirst: Either[Throwable, T] => Unit = elem => p tryComplete elem
@@ -90,8 +103,9 @@ trait ExecutionContext {
/** TODO some docs
*
*/
- def find[T](futures: Traversable[Future[T]])(predicate: T => Boolean): Future[Option[T]] = {
- if (futures.isEmpty) Promise.successful[Option[T]](None).future
+ @implicitNotFound(msg = "Calling this method yields non-deterministic programs.")
+ def find[T](futures: Traversable[Future[T]])(predicate: T => Boolean)(implicit nondet: NonDeterministic): Future[Option[T]] = {
+ if (futures.isEmpty) Promise.kept[Option[T]](None).future
else {
val result = promise[Option[T]]
val count = new AtomicInteger(futures.size)