-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
While there is no technical need to add this for this, we also don't want to block other projects creating adapters. However, this interoperability support is undocumented and as such unsupported. Use at your own risk.
- Loading branch information
1 parent
5f38c49
commit 715a3ae
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace React\Async; | ||
|
||
/** | ||
* This interface 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 interface and the | ||
* FiberFactory. | ||
* | ||
* Usage is not documented and as such not supported and might chang without | ||
* notice. Use at your own risk. | ||
* | ||
* @internal | ||
*/ | ||
interface FiberInterface | ||
{ | ||
public function resume(mixed $value): void; | ||
|
||
public function throw(mixed $throwable): void; | ||
|
||
public function suspend(): mixed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters