|
135 | 135 | * @param ?LoopInterface $loop
|
136 | 136 | * @return PromiseInterface<T>
|
137 | 137 | */
|
138 |
| -function timeout(PromiseInterface $promise, $time, LoopInterface $loop = null) |
| 138 | +function timeout(PromiseInterface $promise, $time, $loop = null) |
139 | 139 | {
|
| 140 | + if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1 |
| 141 | + throw new \InvalidArgumentException('Argument #3 ($loop) expected null|React\EventLoop\LoopInterface'); |
| 142 | + } |
| 143 | + |
140 | 144 | // cancelling this promise will only try to cancel the input promise,
|
141 | 145 | // thus leaving responsibility to the input promise.
|
142 | 146 | $canceller = null;
|
@@ -222,8 +226,12 @@ function timeout(PromiseInterface $promise, $time, LoopInterface $loop = null)
|
222 | 226 | * @param ?LoopInterface $loop
|
223 | 227 | * @return PromiseInterface<void>
|
224 | 228 | */
|
225 |
| -function sleep($time, LoopInterface $loop = null) |
| 229 | +function sleep($time, $loop = null) |
226 | 230 | {
|
| 231 | + if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1 |
| 232 | + throw new \InvalidArgumentException('Argument #2 ($loop) expected null|React\EventLoop\LoopInterface'); |
| 233 | + } |
| 234 | + |
227 | 235 | if ($loop === null) {
|
228 | 236 | $loop = Loop::get();
|
229 | 237 | }
|
@@ -280,7 +288,7 @@ function sleep($time, LoopInterface $loop = null)
|
280 | 288 | * @deprecated 1.8.0 See `sleep()` instead
|
281 | 289 | * @see sleep()
|
282 | 290 | */
|
283 |
| -function resolve($time, LoopInterface $loop = null) |
| 291 | +function resolve($time, $loop = null) |
284 | 292 | {
|
285 | 293 | return sleep($time, $loop)->then(function() use ($time) {
|
286 | 294 | return $time;
|
@@ -317,13 +325,13 @@ function resolve($time, LoopInterface $loop = null)
|
317 | 325 | * $timer->cancel();
|
318 | 326 | * ```
|
319 | 327 | *
|
320 |
| - * @param float $time |
321 |
| - * @param LoopInterface $loop |
| 328 | + * @param float $time |
| 329 | + * @param ?LoopInterface $loop |
322 | 330 | * @return PromiseInterface<never>
|
323 | 331 | * @deprecated 1.8.0 See `sleep()` instead
|
324 | 332 | * @see sleep()
|
325 | 333 | */
|
326 |
| -function reject($time, LoopInterface $loop = null) |
| 334 | +function reject($time, $loop = null) |
327 | 335 | {
|
328 | 336 | return sleep($time, $loop)->then(function () use ($time) {
|
329 | 337 | throw new TimeoutException($time, 'Timer expired after ' . $time . ' seconds');
|
|
0 commit comments