-
-
Save trowski/75febd5008052189182a71f193034fdd to your computer and use it in GitHub Desktop.
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
<?php | |
interface Awaitable | |
{ | |
/** Same as Amp\Promise */ | |
public function onResolve(callable $onResolve): void; | |
} | |
/** | |
* This function returns an instance of Fiber as an implementation detail. | |
* | |
* @param callable $context | |
* @param mixed ...$args | |
* | |
* @return Awaitable | |
*/ | |
function async(callable $context, ...$args): Awaitable { } | |
/** | |
* Suspend the current context until the given awaitable resolves. This method will add a callback to the given | |
* awaitable to call Fiber::resume() or Fiber::throw(). | |
* | |
* @param Awaitable $awaitable | |
* | |
* @return mixed Awaitable resolution value. | |
*/ | |
function await(Awaitable $awaitable): mixed { } | |
final class Fiber implements Awaitable | |
{ | |
/** | |
* @param callable $onResolve | |
*/ | |
public function onResolve(callable $onResolve): void { } | |
/** | |
* @internal Called by async() function. | |
* | |
* Initializes a fiber context. | |
* | |
* @param callable $context | |
* @param mixed ...$args | |
*/ | |
private static function start(callable $context, ...$args): Fiber { } | |
/** | |
* @internal Called by await() function. | |
* | |
* Suspend the current task until the given awaitable resolves. This method will add a callback to the given | |
* awaitable to call Fiber::resume() or Fiber::throw(). | |
* | |
* @param Awaitable $awaitable | |
* | |
* @return mixed Awaitable resolution value. | |
*/ | |
private static function await(Awaitable $awaitable): mixed { } | |
/** | |
* @internal | |
* | |
* Resume the task, the given value is passed into the task as return value of await(). | |
*/ | |
private function resume($v = null): void { } | |
/** | |
* @internal | |
* | |
* Resume the task with an error thrown from await(). | |
*/ | |
private function throw(\Throwable $e): void { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment