1 | <?php |
||
15 | class ReactPromiseAdapter implements Promise |
||
16 | { |
||
17 | /** |
||
18 | * Promise status |
||
19 | * @var string |
||
20 | */ |
||
21 | private $state = Promise::PENDING; |
||
22 | |||
23 | /** |
||
24 | * Adapted React promise |
||
25 | * @var ReactPromise |
||
26 | */ |
||
27 | private $promise; |
||
28 | |||
29 | /** |
||
30 | * PSR7 received response |
||
31 | * @var ResponseInterface |
||
32 | */ |
||
33 | private $response; |
||
34 | |||
35 | /** |
||
36 | * Execution error |
||
37 | * @var Exception |
||
38 | */ |
||
39 | private $exception; |
||
40 | |||
41 | /** |
||
42 | * React Event Loop used for synchronous processing |
||
43 | * @var LoopInterface |
||
44 | */ |
||
45 | private $loop; |
||
46 | |||
47 | /** |
||
48 | * Initialize the promise |
||
49 | * @param ReactPromise $promise |
||
50 | */ |
||
51 | 108 | public function __construct(ReactPromise $promise) |
|
65 | |||
66 | /** |
||
67 | * Allow to apply callable when the promise resolve |
||
68 | * @param callable|null $onFulfilled |
||
69 | * @param callable|null $onRejected |
||
70 | * @return ReactPromiseAdapter |
||
71 | */ |
||
72 | 55 | public function then(callable $onFulfilled = null, callable $onRejected = null) |
|
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | 108 | public function getState() |
|
93 | |||
94 | /** |
||
95 | * Set EventLoop used for synchronous processing |
||
96 | * @param LoopInterface $loop |
||
97 | * @return ReactPromiseAdapter |
||
98 | */ |
||
99 | 108 | public function setLoop(LoopInterface $loop) |
|
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | 108 | public function wait($unwrap = true) |
|
125 | } |
||
126 |