forked from reactphp/async
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiberFactory.php
More file actions
33 lines (28 loc) · 827 Bytes
/
FiberFactory.php
File metadata and controls
33 lines (28 loc) · 827 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
<?php
namespace React\Async;
/**
* This factory its only purpose is interoperability. Where with
* event loops one could simply wrap another event loop. But with fibers
* that has become impossible and as such we provide this factory and the
* FiberInterface.
*
* Usage is not documented and as such not supported and might chang without
* notice. Use at your own risk.
*
* @internal
*/
final class FiberFactory
{
private static ?\Closure $factory = null;
public static function create(): FiberInterface
{
return (self::factory())();
}
public static function factory(?\Closure $factory = null): \Closure
{
if ($factory !== null) {
self::$factory = $factory;
}
return self::$factory ?? static fn (): FiberInterface => new SimpleFiber();
}
}