diff options
author | Philipp Haller <hallerp@gmail.com> | 2012-01-12 13:05:32 +0100 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2012-01-12 13:05:32 +0100 |
commit | 986bbb0914bde62978b18a3dc395b45e993a5812 (patch) | |
tree | 96b3293d624857d5418d899f343616d6e6b95be4 | |
parent | 1126912bce5d098571c1bd29a04e4781e19c3d85 (diff) | |
download | scala-986bbb0914bde62978b18a3dc395b45e993a5812.tar.gz scala-986bbb0914bde62978b18a3dc395b45e993a5812.tar.bz2 scala-986bbb0914bde62978b18a3dc395b45e993a5812.zip |
Update Future.onSuccess to take a PartialFunction.
It has now the same signature as in Akka.
-rw-r--r-- | src/library/scala/concurrent/Future.scala | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index 36126056c9..112d10263f 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -65,16 +65,17 @@ self => /* Callbacks */ /** When this future is completed successfully (i.e. with a value), - * apply the provided function to the value. + * apply the provided partial function to the value if the partial function + * is defined at that value. * * If the future has already been completed with a value, * this will either be applied immediately or be scheduled asynchronously. * * $multipleCallbacks */ - def onSuccess[U](func: T => U): this.type = onComplete { + def onSuccess[U](pf: PartialFunction[T, U]): this.type = onComplete { case Left(t) => // do nothing - case Right(v) => func(v) + case Right(v) if pf isDefinedAt v => pf(v) } /** When this future is completed with a failure (i.e. with a throwable), @@ -243,11 +244,12 @@ self => /** Asynchronously processes the value in the future once the value becomes available. * - * Will not be called if the future times out or fails. - * - * This method typically registers an `onSuccess` callback. + * Will not be called if the future fails. */ - def foreach[U](f: T => U): Unit = onSuccess(f) + def foreach[U](f: T => U): Unit = onComplete { + case Right(r) => f(r) + case Left(_) => // do nothing + } /** Creates a new future by applying a function to the successful result of * this future. If this future is completed with an exception then the new |