Skip to content

Commit 40bb3df

Browse files
committed
Merge pull request scala#2544 from viktorklang/wip-normalize-parameter-names-in-scala-concurrent-2.11-√
Deprecate parameter names in scala.concurrent
2 parents 24efec8 + 44a46f8 commit 40bb3df

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

src/library/scala/concurrent/ExecutionContext.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait ExecutionContext {
2525

2626
/** Reports that an asynchronous computation failed.
2727
*/
28-
def reportFailure(t: Throwable): Unit
28+
def reportFailure(@deprecatedName('t) cause: Throwable): Unit
2929

3030
/** Prepares for the execution of a task. Returns the prepared
3131
* execution context. A valid implementation of `prepare` is one
@@ -83,7 +83,7 @@ object ExecutionContext {
8383

8484
/** The default reporter simply prints the stack trace of the `Throwable` to System.err.
8585
*/
86-
def defaultReporter: Throwable => Unit = (t: Throwable) => t.printStackTrace()
86+
def defaultReporter: Throwable => Unit = _.printStackTrace()
8787
}
8888

8989

src/library/scala/concurrent/Future.scala

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ trait Future[+T] extends Awaitable[T] {
133133
* $multipleCallbacks
134134
* $callbackInContext
135135
*/
136-
def onFailure[U](callback: PartialFunction[Throwable, U])(implicit executor: ExecutionContext): Unit = onComplete {
137-
case Failure(t) if NonFatal(t) && callback.isDefinedAt(t) => callback(t)
136+
def onFailure[U](@deprecatedName('callback) pf: PartialFunction[Throwable, U])(implicit executor: ExecutionContext): Unit = onComplete {
137+
case Failure(t) if NonFatal(t) && pf.isDefinedAt(t) => pf(t)
138138
case _ =>
139139
}(executor)
140140

@@ -147,7 +147,7 @@ trait Future[+T] extends Awaitable[T] {
147147
* $multipleCallbacks
148148
* $callbackInContext
149149
*/
150-
def onComplete[U](func: Try[T] => U)(implicit executor: ExecutionContext): Unit
150+
def onComplete[U](@deprecatedName('func) f: Try[T] => U)(implicit executor: ExecutionContext): Unit
151151

152152

153153
/* Miscellaneous */
@@ -303,21 +303,21 @@ trait Future[+T] extends Awaitable[T] {
303303
* Await.result(h, Duration.Zero) // throw a NoSuchElementException
304304
* }}}
305305
*/
306-
def filter(pred: T => Boolean)(implicit executor: ExecutionContext): Future[T] = {
307-
val p = Promise[T]()
306+
def filter(@deprecatedName('pred) p: T => Boolean)(implicit executor: ExecutionContext): Future[T] = {
307+
val promise = Promise[T]()
308308

309309
onComplete {
310-
case f: Failure[_] => p complete f.asInstanceOf[Failure[T]]
310+
case f: Failure[_] => promise complete f.asInstanceOf[Failure[T]]
311311
case Success(v) =>
312312
try {
313-
if (pred(v)) p success v
314-
else p failure new NoSuchElementException("Future.filter predicate is not satisfied")
313+
if (p(v)) promise success v
314+
else promise failure new NoSuchElementException("Future.filter predicate is not satisfied")
315315
} catch {
316-
case NonFatal(t) => p failure t
316+
case NonFatal(t) => promise failure t
317317
}
318318
}(executor)
319319

320-
p.future
320+
promise.future
321321
}
322322

323323
/** Used by for-comprehensions.
@@ -565,16 +565,16 @@ object Future {
565565
*
566566
* @tparam T the type of the result
567567
* @param body the asychronous computation
568-
* @param execctx the execution context on which the future is run
568+
* @param executor the execution context on which the future is run
569569
* @return the `Future` holding the result of the computation
570570
*/
571-
def apply[T](body: =>T)(implicit execctx: ExecutionContext): Future[T] = impl.Future(body)
571+
def apply[T](body: =>T)(implicit @deprecatedName('execctx) executor: ExecutionContext): Future[T] = impl.Future(body)
572572

573573
/** Simple version of `Futures.traverse`. Transforms a `TraversableOnce[Future[A]]` into a `Future[TraversableOnce[A]]`.
574574
* Useful for reducing many `Future`s into a single `Future`.
575575
*/
576576
def sequence[A, M[_] <: TraversableOnce[_]](in: M[Future[A]])(implicit cbf: CanBuildFrom[M[Future[A]], A, M[A]], executor: ExecutionContext): Future[M[A]] = {
577-
in.foldLeft(Promise.successful(cbf(in)).future) {
577+
in.foldLeft(successful(cbf(in))) {
578578
(fr, fa) => for (r <- fr; a <- fa.asInstanceOf[Future[A]]) yield (r += a)
579579
} map (_.result())
580580
}
@@ -592,15 +592,15 @@ object Future {
592592

593593
/** Returns a `Future` that will hold the optional result of the first `Future` with a result that matches the predicate.
594594
*/
595-
def find[T](futurestravonce: TraversableOnce[Future[T]])(predicate: T => Boolean)(implicit executor: ExecutionContext): Future[Option[T]] = {
596-
val futures = futurestravonce.toBuffer
597-
if (futures.isEmpty) Promise.successful[Option[T]](None).future
595+
def find[T](@deprecatedName('futurestravonce) futures: TraversableOnce[Future[T]])(@deprecatedName('predicate) p: T => Boolean)(implicit executor: ExecutionContext): Future[Option[T]] = {
596+
val futuresBuffer = futures.toBuffer
597+
if (futuresBuffer.isEmpty) successful[Option[T]](None)
598598
else {
599599
val result = Promise[Option[T]]()
600-
val ref = new AtomicInteger(futures.size)
600+
val ref = new AtomicInteger(futuresBuffer.size)
601601
val search: Try[T] => Unit = v => try {
602602
v match {
603-
case Success(r) => if (predicate(r)) result tryComplete Success(Some(r))
603+
case Success(r) if p(r) => result tryComplete Success(Some(r))
604604
case _ =>
605605
}
606606
} finally {
@@ -609,7 +609,7 @@ object Future {
609609
}
610610
}
611611

612-
futures.foreach(_ onComplete search)
612+
futuresBuffer.foreach(_ onComplete search)
613613

614614
result.future
615615
}
@@ -625,9 +625,9 @@ object Future {
625625
* val result = Await.result(Future.fold(futures)(0)(_ + _), 5 seconds)
626626
* }}}
627627
*/
628-
def fold[T, R](futures: TraversableOnce[Future[T]])(zero: R)(foldFun: (R, T) => R)(implicit executor: ExecutionContext): Future[R] = {
629-
if (futures.isEmpty) Promise.successful(zero).future
630-
else sequence(futures).map(_.foldLeft(zero)(foldFun))
628+
def fold[T, R](futures: TraversableOnce[Future[T]])(zero: R)(@deprecatedName('foldFun) op: (R, T) => R)(implicit executor: ExecutionContext): Future[R] = {
629+
if (futures.isEmpty) successful(zero)
630+
else sequence(futures).map(_.foldLeft(zero)(op))
631631
}
632632

633633
/** Initiates a fold over the supplied futures where the fold-zero is the result value of the `Future` that's completed first.
@@ -638,7 +638,7 @@ object Future {
638638
* }}}
639639
*/
640640
def reduce[T, R >: T](futures: TraversableOnce[Future[T]])(op: (R, T) => R)(implicit executor: ExecutionContext): Future[R] = {
641-
if (futures.isEmpty) Promise[R]().failure(new NoSuchElementException("reduce attempted on empty collection")).future
641+
if (futures.isEmpty) failed(new NoSuchElementException("reduce attempted on empty collection"))
642642
else sequence(futures).map(_ reduceLeft op)
643643
}
644644

@@ -651,7 +651,7 @@ object Future {
651651
* }}}
652652
*/
653653
def traverse[A, B, M[_] <: TraversableOnce[_]](in: M[A])(fn: A => Future[B])(implicit cbf: CanBuildFrom[M[A], B, M[B]], executor: ExecutionContext): Future[M[B]] =
654-
in.foldLeft(Promise.successful(cbf(in)).future) { (fr, a) =>
654+
in.foldLeft(successful(cbf(in))) { (fr, a) =>
655655
val fb = fn(a.asInstanceOf[A])
656656
for (r <- fr; b <- fb) yield (r += b)
657657
}.map(_.result())

src/library/scala/concurrent/Promise.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ trait Promise[T] {
8686
*
8787
* $promiseCompletion
8888
*/
89-
def success(v: T): this.type = complete(Success(v))
89+
def success(@deprecatedName('v) value: T): this.type = complete(Success(value))
9090

9191
/** Tries to complete the promise with a value.
9292
*
@@ -104,15 +104,15 @@ trait Promise[T] {
104104
*
105105
* $promiseCompletion
106106
*/
107-
def failure(t: Throwable): this.type = complete(Failure(t))
107+
def failure(@deprecatedName('t) cause: Throwable): this.type = complete(Failure(cause))
108108

109109
/** Tries to complete the promise with an exception.
110110
*
111111
* $nonDeterministic
112112
*
113113
* @return If the promise has already been completed returns `false`, or `true` otherwise.
114114
*/
115-
def tryFailure(t: Throwable): Boolean = tryComplete(Failure(t))
115+
def tryFailure(@deprecatedName('t) cause: Throwable): Boolean = tryComplete(Failure(cause))
116116
}
117117

118118

src/library/scala/concurrent/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ package object concurrent {
2424
*
2525
* @tparam T the type of the result
2626
* @param body the asynchronous computation
27-
* @param execctx the execution context on which the future is run
27+
* @param executor the execution context on which the future is run
2828
* @return the `Future` holding the result of the computation
2929
*/
30-
def future[T](body: =>T)(implicit execctx: ExecutionContext): Future[T] = Future[T](body)
30+
def future[T](body: =>T)(implicit @deprecatedName('execctx) executor: ExecutionContext): Future[T] = Future[T](body)
3131

3232
/** Creates a promise object which can be completed with a value or an exception.
3333
*

0 commit comments

Comments
 (0)