|
4 | 4 |
|
5 | 5 | use Exception; |
6 | 6 | use React\EventLoop\Factory; |
7 | | -use React\EventLoop\LoopInterface; |
8 | 7 | use React\Promise\Promise; |
9 | 8 | use function React\Promise\all; |
10 | 9 | use function React\Promise\race; |
|
14 | 13 | describe('async', function () { |
15 | 14 | describe('with simple promise', function () { |
16 | 15 | it('should return promise with value', function () { |
17 | | - $resultValue = null; |
18 | | - |
19 | 16 | asyncRun(function () { |
20 | 17 | return yield resolve('val'); |
21 | 18 | })->then(function ($res) { |
|
82 | 79 | }); |
83 | 80 | describe('with loop', function () { |
84 | 81 | given('loop', function () { |
85 | | - return $loop = Factory::create(); |
| 82 | + return Factory::create(); |
86 | 83 | }); |
87 | 84 | given('wait', function () { |
88 | 85 | return function ($time) { |
|
98 | 95 | }); |
99 | 96 |
|
100 | 97 | it('should work fine with loop based promises', function () { |
101 | | - /** @var LoopInterface $loop */ |
102 | | - $loop = $this->loop; |
103 | | - |
104 | 98 | $this->time = microtime(true); |
105 | 99 | $onResolve = function ($res) { |
106 | 100 | $this->result = $res; |
107 | 101 | $this->time = microtime(true) - $this->time; |
| 102 | + $this->loop->stop(); |
108 | 103 | }; |
109 | 104 | $onReject = function ($reason) { |
110 | 105 | }; |
|
128 | 123 | }; |
129 | 124 | async($async("initial value"))->then($onResolve, $onReject); |
130 | 125 |
|
131 | | - $loop->addTimer(0.41, function () use ($loop) { |
132 | | - $loop->stop(); |
133 | | - }); |
134 | | - |
135 | | - $loop->run(); |
| 126 | + $this->loop->run(); |
136 | 127 | expect($this->result)->toBe('wow'); |
137 | 128 | expect($this->time)->toBeGreaterThan(0.4); |
138 | 129 | expect($this->time)->toBeLessThan(0.41); |
|
0 commit comments