From 0ada84311adcd41190768ee7fd4010ca92be1140 Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Wed, 18 Jul 2012 03:41:14 +0300 Subject: [PATCH] Update text about `onComplete`, `onSuccess`, and `onFailure` (result type and execution ordering). --- sips/pending/_posts/2012-01-21-futures-promises.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sips/pending/_posts/2012-01-21-futures-promises.md b/sips/pending/_posts/2012-01-21-futures-promises.md index 5973b09d2a..ff933b28d0 100644 --- a/sips/pending/_posts/2012-01-21-futures-promises.md +++ b/sips/pending/_posts/2012-01-21-futures-promises.md @@ -131,14 +131,18 @@ To handle failed results, the `onFailure` callback is used: f onFailure { case t => render("An error has occured: " + t.getMessage) - } onSuccess { + } + f onSuccess { case posts => for (post <- posts) render(post) } The `onFailure` callback is only executed if the future fails, that is, if it contains an exception. The `onComplete`, `onSuccess`, and -`onFailure` methods return the receiver (the future), which allows -registering multiple callbacks by chaining invocations. +`onFailure` methods have result type `Unit`, which means invocations +of these methods cannot be chained. This is an intentional design +decision which was made to avoid suggesting that chained +invocations may imply an ordering on the execution of the registered +callbacks (callbacks registered on the same future are unordered). Since partial functions have the `isDefinedAt` method, the `onFailure` method only triggers the callback if it is defined for a