PluginProbe
DecaLog / 3.0.2
DecaLog v3.0.2
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 / react / Promise / Deferred.php

Deferred.php in DecaLog 3.0.2, at includes/libraries/react/Promise/Deferred.php

66 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace React\Promise;
4
5 class Deferred implements PromisorInterface
6 {
7 private $promise;
8 private $resolveCallback;
9 private $rejectCallback;
10 private $notifyCallback;
11 private $canceller;
12
13 public function __construct(callable $canceller = null)
14 {
15 $this->canceller = $canceller;
16 }
17
18 public function promise()
19 {
20 if (null === $this->promise) {
21 $this->promise = new Promise(function ($resolve, $reject, $notify) {
22 $this->resolveCallback = $resolve;
23 $this->rejectCallback = $reject;
24 $this->notifyCallback = $notify;
25 }, $this->canceller);
26 $this->canceller = null;
27 }
28
29 return $this->promise;
30 }
31
32 public function resolve($value = null)
33 {
34 $this->promise();
35
36 \call_user_func($this->resolveCallback, $value);
37 }
38
39 public function reject($reason = null)
40 {
41 $this->promise();
42
43 \call_user_func($this->rejectCallback, $reason);
44 }
45
46 /**
47 * @deprecated 2.6.0 Progress support is deprecated and should not be used anymore.
48 * @param mixed $update
49 */
50 public function notify($update = null)
51 {
52 $this->promise();
53
54 \call_user_func($this->notifyCallback, $update);
55 }
56
57 /**
58 * @deprecated 2.2.0
59 * @see Deferred::notify()
60 */
61 public function progress($update = null)
62 {
63 $this->notify($update);
64 }
65 }
66