File tree Expand file tree Collapse file tree 1 file changed +4
-16
lines changed Expand file tree Collapse file tree 1 file changed +4
-16
lines changed Original file line number Diff line number Diff line change @@ -7,39 +7,27 @@ final class Deferred implements PromisorInterface
7
7
private $ promise ;
8
8
private $ resolveCallback ;
9
9
private $ rejectCallback ;
10
- private $ canceller ;
11
10
12
11
public function __construct (callable $ canceller = null )
13
12
{
14
- $ this ->canceller = $ canceller ;
13
+ $ this ->promise = new Promise (function ($ resolve , $ reject ): void {
14
+ $ this ->resolveCallback = $ resolve ;
15
+ $ this ->rejectCallback = $ reject ;
16
+ }, $ canceller );
15
17
}
16
18
17
19
public function promise (): PromiseInterface
18
20
{
19
- if (null === $ this ->promise ) {
20
- $ canceller = $ this ->canceller ;
21
- $ this ->canceller = null ;
22
-
23
- $ this ->promise = new Promise (function ($ resolve , $ reject ): void {
24
- $ this ->resolveCallback = $ resolve ;
25
- $ this ->rejectCallback = $ reject ;
26
- }, $ canceller );
27
- }
28
-
29
21
return $ this ->promise ;
30
22
}
31
23
32
24
public function resolve ($ value = null ): void
33
25
{
34
- $ this ->promise ();
35
-
36
26
($ this ->resolveCallback )($ value );
37
27
}
38
28
39
29
public function reject (\Throwable $ reason ): void
40
30
{
41
- $ this ->promise ();
42
-
43
31
($ this ->rejectCallback )($ reason );
44
32
}
45
33
}
You can’t perform that action at this time.
0 commit comments