PluginProbe
DecaLog / 4.4.0
DecaLog v4.4.0
3.0.2 3.1.0 3.10.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 3.7.1 3.8.0 3.9.0 3.9.1 4.0.0 4.1.0 4.2.0 4.3.0 4.3.1 4.4.0 4.5.0 All 75 releases
decalog / includes / libraries / http / promise / RejectedPromise.php

RejectedPromise.php in DecaLog 4.4.0, at includes/libraries/http/promise/RejectedPromise.php

49 lines 890 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Http\Promise;
4
5 /**
6 * A rejected promise.
7 *
8 * @author Joel Wurtz <[email protected]>
9 */
10 final class RejectedPromise implements Promise
11 {
12 /**
13 * @var \Throwable
14 */
15 private $exception;
16
17 public function __construct(\Throwable $exception)
18 {
19 $this->exception = $exception;
20 }
21
22 public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
23 {
24 if (null === $onRejected) {
25 return $this;
26 }
27
28 try {
29 return new FulfilledPromise($onRejected($this->exception));
30 } catch (\Exception $e) {
31 return new self($e);
32 }
33 }
34
35 public function getState()
36 {
37 return Promise::REJECTED;
38 }
39
40 public function wait($unwrap = true)
41 {
42 if ($unwrap) {
43 throw $this->exception;
44 }
45
46 return null;
47 }
48 }
49