1
0
mirror of https://github.com/danog/amp.git synced 2024-12-12 09:29:45 +01:00
amp/stubs/Fiber.php

79 lines
2.4 KiB
PHP
Raw Normal View History

2020-09-24 18:52:22 +02:00
<?php
final class Fiber
{
/**
2020-11-21 07:18:14 +01:00
* @param callable $callback Function to invoke when running the fiber.
*/
public static function create(callable $callback): Fiber { }
/**
* Starts execution of the fiber. Returns when the fiber suspends or terminates.
*
* Must be called within {@see FiberScheduler::run()}.
*
* @param mixed ...$args Arguments passed to fiber function.
*/
public function start(mixed ...$args): void { }
/**
* Resumes the fiber, returning the given value from {@see Fiber::suspend()}.
* Returns when the fiber suspends or terminates.
*
* Must be called within {@see FiberScheduler::run()}.
*
* @param mixed $value
*
* @throw FiberError If the fiber is running or terminated.
*/
public function resume(mixed $value = null): void { }
/**
* Throws the given exception into the fiber from {@see Fiber::suspend()}.
* Returns when the fiber suspends or terminates.
*
* Must be called within {@see FiberScheduler::run()}.
2020-09-24 18:52:22 +02:00
*
2020-11-21 07:18:14 +01:00
* @param Throwable $exception
*
* @throw FiberError If the fiber is running or terminated.
2020-09-24 18:52:22 +02:00
*/
2020-11-21 07:18:14 +01:00
public function throw(Throwable $exception): void { }
2020-09-24 18:52:22 +02:00
/**
2020-11-21 07:18:14 +01:00
* @return bool True if the fiber is suspended.
*/
public function isSuspended(): bool { }
/**
* @return bool True if the fiber is currently running.
*/
public function isRunning(): bool { }
/**
* @return bool True if the fiber has completed execution.
*/
public function isTerminated(): bool { }
/**
* Suspend execution of the fiber. The Fiber object is provided as the first argument to the given callback.
* The fiber may be resumed with {@see Fiber::resume()} or {@see Fiber::throw()}.
*
* Cannot be called within {@see FiberScheduler::run()}.
2020-09-24 18:52:22 +02:00
*
* @param callable(Fiber):void $enqueue
2020-09-24 18:52:22 +02:00
* @param FiberScheduler $scheduler
*
2020-11-21 07:18:14 +01:00
* @return mixed Value provided to {@see Fiber::resume()}.
2020-09-24 18:52:22 +02:00
*
2020-11-21 07:18:14 +01:00
* @throws FiberError Thrown if within {@see FiberScheduler::run()} or within a callback given to this method.
* @throws Throwable Exception provided to {@see Fiber::throw()}.
2020-09-24 18:52:22 +02:00
*/
public static function suspend(callable $enqueue, FiberScheduler $scheduler): mixed { }
2020-11-05 18:29:31 +01:00
/**
2020-11-21 07:18:14 +01:00
* Private constructor to force use of {@see create()}.
2020-11-05 18:29:31 +01:00
*/
private function __construct() { }
2020-09-24 18:52:22 +02:00
}