From aac015a84c2d64ce485078a5a854bc7533e2fc7b Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Fri, 8 Nov 2013 15:59:04 +0100 Subject: SI-7958 Deprecate methods `future` and `promise` in the `scala.concurrent` package object - The corresponding `apply` methods in the `Future` and `Promise` objects should be used instead. - Adjusted tests to use non-deprecated versions - Fixed doc comments not to use deprecated methods - Added comment about planned removal in 2.13.0 --- src/library/scala/concurrent/Future.scala | 28 ++++++++++++++-------------- src/library/scala/concurrent/package.scala | 4 ++++ 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index b9f73c2872..dd86af0dd4 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -29,11 +29,11 @@ import scala.reflect.ClassTag /** The trait that represents futures. * - * Asynchronous computations that yield futures are created with the `future` call: + * Asynchronous computations that yield futures are created with the `Future` call: * * {{{ * val s = "Hello" - * val f: Future[String] = future { + * val f: Future[String] = Future { * s + " future!" * } * f onSuccess { @@ -67,8 +67,8 @@ import scala.reflect.ClassTag * Example: * * {{{ - * val f = future { 5 } - * val g = future { 3 } + * val f = Future { 5 } + * val g = Future { 3 } * val h = for { * x: Int <- f // returns Future(5) * y: Int <- g // returns Future(3) @@ -266,7 +266,7 @@ trait Future[+T] extends Awaitable[T] { * * Example: * {{{ - * val f = future { 5 } + * val f = Future { 5 } * val g = f filter { _ % 2 == 1 } * val h = f filter { _ % 2 == 0 } * Await.result(g, Duration.Zero) // evaluates to 5 @@ -291,7 +291,7 @@ trait Future[+T] extends Awaitable[T] { * * Example: * {{{ - * val f = future { -5 } + * val f = Future { -5 } * val g = f collect { * case x if x < 0 => -x * } @@ -314,9 +314,9 @@ trait Future[+T] extends Awaitable[T] { * Example: * * {{{ - * future (6 / 0) recover { case e: ArithmeticException => 0 } // result: 0 - * future (6 / 0) recover { case e: NotFoundException => 0 } // result: exception - * future (6 / 2) recover { case e: ArithmeticException => 0 } // result: 3 + * Future (6 / 0) recover { case e: ArithmeticException => 0 } // result: 0 + * Future (6 / 0) recover { case e: NotFoundException => 0 } // result: exception + * Future (6 / 2) recover { case e: ArithmeticException => 0 } // result: 3 * }}} */ def recover[U >: T](pf: PartialFunction[Throwable, U])(implicit executor: ExecutionContext): Future[U] = { @@ -334,8 +334,8 @@ trait Future[+T] extends Awaitable[T] { * Example: * * {{{ - * val f = future { Int.MaxValue } - * future (6 / 0) recoverWith { case e: ArithmeticException => f } // result: Int.MaxValue + * val f = Future { Int.MaxValue } + * Future (6 / 0) recoverWith { case e: ArithmeticException => f } // result: Int.MaxValue * }}} */ def recoverWith[U >: T](pf: PartialFunction[Throwable, Future[U]])(implicit executor: ExecutionContext): Future[U] = { @@ -373,8 +373,8 @@ trait Future[+T] extends Awaitable[T] { * * Example: * {{{ - * val f = future { sys.error("failed") } - * val g = future { 5 } + * val f = Future { sys.error("failed") } + * val g = Future { 5 } * val h = f fallbackTo g * Await.result(h, Duration.Zero) // evaluates to 5 * }}} @@ -416,7 +416,7 @@ trait Future[+T] extends Awaitable[T] { * The following example prints out `5`: * * {{{ - * val f = future { 5 } + * val f = Future { 5 } * f andThen { * case r => sys.error("runtime exception") * } andThen { diff --git a/src/library/scala/concurrent/package.scala b/src/library/scala/concurrent/package.scala index 2fe14a9c1a..cc1350f5a9 100644 --- a/src/library/scala/concurrent/package.scala +++ b/src/library/scala/concurrent/package.scala @@ -27,6 +27,8 @@ package object concurrent { * @param executor the execution context on which the future is run * @return the `Future` holding the result of the computation */ + @deprecated("Use `Future { ... }` instead.", "2.11.0") + // removal planned for 2.13.0 def future[T](body: =>T)(implicit @deprecatedName('execctx) executor: ExecutionContext): Future[T] = Future[T](body) /** Creates a promise object which can be completed with a value or an exception. @@ -34,6 +36,8 @@ package object concurrent { * @tparam T the type of the value in the promise * @return the newly created `Promise` object */ + @deprecated("Use `Promise[T]()` instead.", "2.11.0") + // removal planned for 2.13.0 def promise[T](): Promise[T] = Promise[T]() /** Used to designate a piece of code which potentially blocks, allowing the current [[BlockContext]] to adjust -- cgit v1.2.3