scala/scala — pull request #4042 by viktorklang (2014-10-09 13:14:51+00:00)
Title: SIP-14 improvements

Add missing canonical combinators:
`def transform[S](f: Try[T] => Try[S])(implicit executor: ExecutionContext): Future[S]`
`def transformWith[S](f: Try[T] => Future[S])(implicit executor: ExecutionContext): Future[S]`
`def flatten[S](implicit ev: T <:< Future[S]): Future[S]`

Add missing utilities:
`val unit: Future[Unit]` in `object Future`
`val never: Future[Nothing]` in `object Future`
`def defaultBlockContext: BlockContext` in `object BlockContext`

Refactors:
the scala.concurrent.Future trait to not explicit create any Promises,
so that implementations can control implementation type,
this is mainly facilitated through adding of the `transform` and `transformWith` methods.
the implementation of ExecutionContextImpl has been cleaned up

Securing:
Add a self-check in completeWith and tryCompleteWith to avoid cycles in trait Promise
Capping the maximum number of Threads for the global ExecutionContext to the max parallelism
Implementing (almost) all `Future` combinators on `transformWith` and `transform` means
that DefaultPromise linking works on both (flat)map and recover(With)
Nested `blocking {}` should not spawn extra threads beyond the first.

Removes:
the private internalExecutor method in favor of an import in trait Future
the private internalExecutor method in favor of an import in trait Promise
the AtomicReferenceFieldUpdater in AbstractPromise since we're using Unsafe
scala.concurrent.impl.Future is no longer needed

Deprecates:
Future.onSuccess - discourage the use of callbacks
(and is also redundant considering `foreach` and `onComplete`)
Future.onFailure - discourage the use of callbacks
(and is also redundant considering `onComplete` and `failed.foreach`)
ExecutionContext.prepare - it was ill specced and it is too easy to forget to call it
(or even know when to call it or call it more times than needed)

Reimplements:
failed - in terms of `transform`
map - in terms of `transform`
flatMap - in terms of `transformWith`
recover - in terms of `transform`
recoverWith - in terms of `transformWith`
zip - in terms of `flatMap` + `map`
fallbackTo - in terms of `recoverWith` + `recoverWith`
andThen - in terms of `transform`

Miscellaneous:
Giving the threads of ExecutionContext.global sensible names

Documentation:
Almost all methods on Future and Promise have been revisited and had their ScalaDoc updated

Tests:
Yes