| 1 |
<?php |
| 2 |
|
| 3 |
namespace React\Async; |
| 4 |
|
| 5 |
use React\Promise\PromiseInterface; |
| 6 |
|
| 7 |
/** |
| 8 |
* @internal |
| 9 |
* |
| 10 |
* @template T |
| 11 |
*/ |
| 12 |
final class FiberMap |
| 13 |
{ |
| 14 |
/** @var array<int,PromiseInterface<T>> */ |
| 15 |
private static array $map = []; |
| 16 |
|
| 17 |
/** |
| 18 |
* @param \Fiber<mixed,mixed,mixed,mixed> $fiber |
| 19 |
* @param PromiseInterface<T> $promise |
| 20 |
*/ |
| 21 |
public static function setPromise(\Fiber $fiber, PromiseInterface $promise): void |
| 22 |
{ |
| 23 |
self::$map[\spl_object_id($fiber)] = $promise; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* @param \Fiber<mixed,mixed,mixed,mixed> $fiber |
| 28 |
*/ |
| 29 |
public static function unsetPromise(\Fiber $fiber): void |
| 30 |
{ |
| 31 |
unset(self::$map[\spl_object_id($fiber)]); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* @param \Fiber<mixed,mixed,mixed,mixed> $fiber |
| 36 |
* @return ?PromiseInterface<T> |
| 37 |
*/ |
| 38 |
public static function getPromise(\Fiber $fiber): ?PromiseInterface |
| 39 |
{ |
| 40 |
return self::$map[\spl_object_id($fiber)] ?? null; |
| 41 |
} |
| 42 |
} |