forked from reactphp/async
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiberMap.php
More file actions
42 lines (36 loc) · 924 Bytes
/
FiberMap.php
File metadata and controls
42 lines (36 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace React\Async;
use React\Promise\PromiseInterface;
/**
* @internal
*
* @template T
*/
final class FiberMap
{
/** @var array<int,PromiseInterface<T>> */
private static array $map = [];
/**
* @param \Fiber<mixed,mixed,mixed,mixed> $fiber
* @param PromiseInterface<T> $promise
*/
public static function setPromise(\Fiber $fiber, PromiseInterface $promise): void
{
self::$map[\spl_object_id($fiber)] = $promise;
}
/**
* @param \Fiber<mixed,mixed,mixed,mixed> $fiber
*/
public static function unsetPromise(\Fiber $fiber): void
{
unset(self::$map[\spl_object_id($fiber)]);
}
/**
* @param \Fiber<mixed,mixed,mixed,mixed> $fiber
* @return ?PromiseInterface<T>
*/
public static function getPromise(\Fiber $fiber): ?PromiseInterface
{
return self::$map[\spl_object_id($fiber)] ?? null;
}
}