-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathFiberMap.php
More file actions
62 lines (50 loc) · 1.34 KB
/
FiberMap.php
File metadata and controls
62 lines (50 loc) · 1.34 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
<?php
namespace React\Async;
use React\Promise\PromiseInterface;
/**
* @internal
*/
final class FiberMap
{
private static ?\WeakMap $status = null;
private static ?\WeakMap $map = null;
public static function register(\Fiber $fiber): void
{
if (self::$status === null) {
self::$status = new \WeakMap();
}
if (self::$map === null) {
self::$map = new \WeakMap();
}
self::$status[$fiber] = false;
self::$map[$fiber] = [];
}
public static function cancel(\Fiber $fiber): void
{
self::$status[$fiber] = true;
}
public static function isCancelled(\Fiber $fiber): bool
{
return self::$status[$fiber] ?? false;
}
public static function setPromise(\Fiber $fiber, PromiseInterface $promise): void
{
self::$map[$fiber] = $promise;
}
public static function unsetPromise(\Fiber $fiber): void
{
unset(self::$map[$fiber]);
}
public static function has(\Fiber $fiber): bool
{
return array_key_exists($fiber, self::$map);
}
public static function getPromise(\Fiber $fiber): ?PromiseInterface
{
return self::$map[$fiber] ?? null;
}
public static function unregister(\Fiber $fiber): void
{
unset(self::$status[$fiber], self::$map[$fiber]);
}
}