@@ -29,9 +29,11 @@ Table of Contents
2929 * [ PromiseInterface] ( #promiseinterface )
3030 * [ PromiseInterface::then()] ( #promiseinterfacethen )
3131 * [ PromiseInterface::done()] ( #promiseinterfacedone )
32- * [ PromiseInterface::otherwise ()] ( #promiseinterfaceotherwise )
33- * [ PromiseInterface::always ()] ( #promiseinterfacealways )
32+ * [ PromiseInterface::catch ()] ( #promiseinterfacecatch )
33+ * [ PromiseInterface::finally ()] ( #promiseinterfacefinally )
3434 * [ PromiseInterface::cancel()] ( #promiseinterfacecancel )
35+ * [ ~~ PromiseInterface::otherwise()~~ ] ( #promiseinterfaceotherwise )
36+ * [ ~~ PromiseInterface::always()~~ ] ( #promiseinterfacealways )
3537 * [ Promise] ( #promise-2 )
3638 * [ Functions] ( #functions )
3739 * [ resolve()] ( #resolve )
@@ -206,10 +208,10 @@ Since the purpose of `done()` is consumption rather than transformation,
206208* [ PromiseInterface::then()] ( #promiseinterfacethen )
207209* [ done() vs. then()] ( #done-vs-then )
208210
209- #### PromiseInterface::otherwise ()
211+ #### PromiseInterface::catch ()
210212
211213``` php
212- $promise->otherwise (callable $onRejected);
214+ $promise->catch (callable $onRejected);
213215```
214216
215217Registers a rejection handler for promise. It is a shortcut for:
@@ -223,19 +225,19 @@ only specific errors.
223225
224226``` php
225227$promise
226- ->otherwise (function (\RuntimeException $reason) {
228+ ->catch (function (\RuntimeException $reason) {
227229 // Only catch \RuntimeException instances
228230 // All other types of errors will propagate automatically
229231 })
230- ->otherwise (function (\Throwable $reason) {
232+ ->catch (function (\Throwable $reason) {
231233 // Catch other errors
232234 });
233235```
234236
235- #### PromiseInterface::always ()
237+ #### PromiseInterface::finally ()
236238
237239``` php
238- $newPromise = $promise->always (callable $onFulfilledOrRejected);
240+ $newPromise = $promise->finally (callable $onFulfilledOrRejected);
239241```
240242
241243Allows you to execute "cleanup" type tasks in a promise chain.
@@ -254,15 +256,15 @@ when the promise is either fulfilled or rejected.
254256 rejected promise, ` $newPromise ` will reject with the thrown exception or
255257 rejected promise's reason.
256258
257- ` always ()` behaves similarly to the synchronous finally statement. When combined
258- with ` otherwise ()` , ` always ()` allows you to write code that is similar to the familiar
259+ ` finally ()` behaves similarly to the synchronous finally statement. When combined
260+ with ` catch ()` , ` finally ()` allows you to write code that is similar to the familiar
259261synchronous catch/finally pair.
260262
261263Consider the following synchronous code:
262264
263265``` php
264266try {
265- return doSomething();
267+ return doSomething();
266268} catch (\Throwable $e) {
267269 return handleError($e);
268270} finally {
@@ -275,8 +277,8 @@ written:
275277
276278``` php
277279return doSomething()
278- ->otherwise ('handleError')
279- ->always ('cleanup');
280+ ->catch ('handleError')
281+ ->finally ('cleanup');
280282```
281283
282284#### PromiseInterface::cancel()
@@ -291,6 +293,32 @@ further interest in the results of the operation.
291293Once a promise is settled (either fulfilled or rejected), calling ` cancel() ` on
292294a promise has no effect.
293295
296+ #### ~~ PromiseInterface::otherwise()~~
297+
298+ > Deprecated since v3.0.0, see [ ` catch() ` ] ( #promiseinterfacecatch ) instead.
299+
300+ The ` otherwise() ` method registers a rejection handler for a promise.
301+
302+ This method continues to exist only for BC reasons and to ease upgrading
303+ between versions. It is an alias for:
304+
305+ ``` php
306+ $promise->catch($onRejected);
307+ ```
308+
309+ #### ~~ PromiseInterface::always()~~
310+
311+ > Deprecated since v3.0.0, see [ ` finally() ` ] ( #promiseinterfacefinally ) instead.
312+
313+ The ` always() ` method allows you to execute "cleanup" type tasks in a promise chain.
314+
315+ This method continues to exist only for BC reasons and to ease upgrading
316+ between versions. It is an alias for:
317+
318+ ``` php
319+ $promise->finally($onFulfilledOrRejected);
320+ ```
321+
294322### Promise
295323
296324Creates a promise whose state is controlled by the functions passed to
@@ -559,17 +587,17 @@ $deferred->promise()
559587 ->then(function ($x) {
560588 throw new \Exception($x + 1);
561589 })
562- ->otherwise (function (\Exception $x) {
590+ ->catch (function (\Exception $x) {
563591 // Propagate the rejection
564592 throw $x;
565593 })
566- ->otherwise (function (\Exception $x) {
594+ ->catch (function (\Exception $x) {
567595 // Can also propagate by returning another rejection
568596 return React\Promise\reject(
569597 new \Exception($x->getMessage() + 1)
570598 );
571599 })
572- ->otherwise (function ($x) {
600+ ->catch (function ($x) {
573601 echo 'Reject ' . $x->getMessage(); // 3
574602 });
575603
@@ -591,7 +619,7 @@ $deferred->promise()
591619 ->then(function ($x) {
592620 throw new \Exception($x + 1);
593621 })
594- ->otherwise (function (\Exception $x) {
622+ ->catch (function (\Exception $x) {
595623 // Handle the rejection, and don't propagate.
596624 // This is like catch without a rethrow
597625 return $x->getMessage() + 1;
0 commit comments