Debian Codegraph @

vendor/react/async/src/FiberFactory.php

raw
1 <?php
2
3 namespace React\Async;
4
5 /**
6 * This factory its only purpose is interoperability. Where with
7 * event loops one could simply wrap another event loop. But with fibers
8 * that has become impossible and as such we provide this factory and the
9 * FiberInterface.
10 *
11 * Usage is not documented and as such not supported and might chang without
12 * notice. Use at your own risk.
13 *
14 * @internal
15 */
16 final class FiberFactory
17 {
18 private static ?\Closure $factory = null;
19
20 public static function create(): FiberInterface
21 {
22 return (self::factory())();
23 }
24
25 public static function factory(?\Closure $factory = null): \Closure
26 {
27 if ($factory !== null) {
28 self::$factory = $factory;
29 }
30
31 return self::$factory ?? static fn (): FiberInterface => new SimpleFiber();
32 }
33 }