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
64 lines (54 loc) · 1.61 KB
/
FiberMap.php
File metadata and controls
64 lines (54 loc) · 1.61 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace React\Async;
use React\Promise\PromiseInterface;
/**
* @internal
*
* @template T
*/
final class FiberMap
{
/** @var array<int,bool> */
private static array $status = [];
/** @var array<int,PromiseInterface<T>> */
private static array $map = [];
/** @param \Fiber<mixed,mixed,mixed,mixed> $fiber */
public static function register(\Fiber $fiber): void
{
self::$status[\spl_object_id($fiber)] = false;
}
/** @param \Fiber<mixed,mixed,mixed,mixed> $fiber */
public static function cancel(\Fiber $fiber): void
{
self::$status[\spl_object_id($fiber)] = true;
}
/**
* @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
* @param PromiseInterface<T> $promise
*/
public static function unsetPromise(\Fiber $fiber, PromiseInterface $promise): 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;
}
/** @param \Fiber<mixed,mixed,mixed,mixed> $fiber */
public static function unregister(\Fiber $fiber): void
{
unset(self::$status[\spl_object_id($fiber)], self::$map[\spl_object_id($fiber)]);
}
}