@@ -29,8 +29,10 @@ Table of Contents
29
29
* [ PromiseInterface] ( #promiseinterface )
30
30
* [ PromiseInterface::then()] ( #promiseinterfacethen )
31
31
* [ PromiseInterface::done()] ( #promiseinterfacedone )
32
- * [ PromiseInterface::otherwise()] ( #promiseinterfaceotherwise )
33
- * [ PromiseInterface::always()] ( #promiseinterfacealways )
32
+ * [ ~~ PromiseInterface::otherwise()~~ ] ( #promiseinterfaceotherwise )
33
+ * [ PromiseInterface::catch()] ( #promiseinterfacecatch )
34
+ * [ ~~ PromiseInterface::always()~~ ] ( #promiseinterfacealways )
35
+ * [ PromiseInterface::finally()] ( #promiseinterfacefinally )
34
36
* [ PromiseInterface::cancel()] ( #promiseinterfacecancel )
35
37
* [ Promise] ( #promise-2 )
36
38
* [ Functions] ( #functions )
@@ -206,10 +208,14 @@ Since the purpose of `done()` is consumption rather than transformation,
206
208
* [ PromiseInterface::then()] ( #promiseinterfacethen )
207
209
* [ done() vs. then()] ( #done-vs-then )
208
210
209
- #### PromiseInterface::otherwise()
211
+ #### ~~ PromiseInterface::otherwise()~~
212
+
213
+ The ` otherwise ` method has been deprecated in favour of [ ` catch ` ] ( #promiseinterfacecatch )
214
+
215
+ #### PromiseInterface::catch()
210
216
211
217
``` php
212
- $promise->otherwise (callable $onRejected);
218
+ $promise->catch (callable $onRejected);
213
219
```
214
220
215
221
Registers a rejection handler for promise. It is a shortcut for:
@@ -223,19 +229,23 @@ only specific errors.
223
229
224
230
``` php
225
231
$promise
226
- ->otherwise (function (\RuntimeException $reason) {
232
+ ->catch (function (\RuntimeException $reason) {
227
233
// Only catch \RuntimeException instances
228
234
// All other types of errors will propagate automatically
229
235
})
230
- ->otherwise (function (\Throwable $reason) {
236
+ ->catch (function (\Throwable $reason) {
231
237
// Catch other errors
232
238
});
233
239
```
234
240
235
- #### PromiseInterface::always()
241
+ #### ~~ PromiseInterface::always()~~
242
+
243
+ The ` otherwise ` method has been deprecated in favour of [ ` finally ` ] ( #promiseinterfacefinally )
244
+
245
+ #### PromiseInterface::finally()
236
246
237
247
``` php
238
- $newPromise = $promise->always (callable $onFulfilledOrRejected);
248
+ $newPromise = $promise->finally (callable $onFulfilledOrRejected);
239
249
```
240
250
241
251
Allows you to execute "cleanup" type tasks in a promise chain.
@@ -254,8 +264,8 @@ when the promise is either fulfilled or rejected.
254
264
rejected promise, ` $newPromise ` will reject with the thrown exception or
255
265
rejected promise's reason.
256
266
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
267
+ ` finally ()` behaves similarly to the synchronous finally statement. When combined
268
+ with ` catch ()` , ` finally ()` allows you to write code that is similar to the familiar
259
269
synchronous catch/finally pair.
260
270
261
271
Consider the following synchronous code:
@@ -275,8 +285,8 @@ written:
275
285
276
286
``` php
277
287
return doSomething()
278
- ->otherwise ('handleError')
279
- ->always ('cleanup');
288
+ ->catch ('handleError')
289
+ ->finally ('cleanup');
280
290
```
281
291
282
292
#### PromiseInterface::cancel()
@@ -559,17 +569,17 @@ $deferred->promise()
559
569
->then(function ($x) {
560
570
throw new \Exception($x + 1);
561
571
})
562
- ->otherwise (function (\Exception $x) {
572
+ ->catch (function (\Exception $x) {
563
573
// Propagate the rejection
564
574
throw $x;
565
575
})
566
- ->otherwise (function (\Exception $x) {
576
+ ->catch (function (\Exception $x) {
567
577
// Can also propagate by returning another rejection
568
578
return React\Promise\reject(
569
579
new \Exception($x->getMessage() + 1)
570
580
);
571
581
})
572
- ->otherwise (function ($x) {
582
+ ->catch (function ($x) {
573
583
echo 'Reject ' . $x->getMessage(); // 3
574
584
});
575
585
@@ -591,7 +601,7 @@ $deferred->promise()
591
601
->then(function ($x) {
592
602
throw new \Exception($x + 1);
593
603
})
594
- ->otherwise (function (\Exception $x) {
604
+ ->catch (function (\Exception $x) {
595
605
// Handle the rejection, and don't propagate.
596
606
// This is like catch without a rethrow
597
607
return $x->getMessage() + 1;
0 commit comments