2020-09-24 18:52:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class Fiber
|
|
|
|
{
|
|
|
|
/**
|
2020-12-16 05:17:49 +01:00
|
|
|
* @param callable $callback Function to invoke when starting the fiber.
|
2020-11-21 07:18:14 +01:00
|
|
|
*/
|
2020-12-16 05:17:49 +01:00
|
|
|
public function __construct(callable $callback) { }
|
2020-11-21 07:18:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts execution of the fiber. Returns when the fiber suspends or terminates.
|
|
|
|
*
|
2021-01-04 04:30:43 +01:00
|
|
|
* Must be called within a {@see FiberScheduler}.
|
2020-11-21 07:18:14 +01:00
|
|
|
*
|
|
|
|
* @param mixed ...$args Arguments passed to fiber function.
|
2020-12-09 18:22:47 +01:00
|
|
|
*
|
|
|
|
* @throw FiberError If the fiber is running or terminated.
|
|
|
|
* @throw Throwable If the fiber callable throws an uncaught exception.
|
2020-11-21 07:18:14 +01:00
|
|
|
*/
|
|
|
|
public function start(mixed ...$args): void { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resumes the fiber, returning the given value from {@see Fiber::suspend()}.
|
|
|
|
* Returns when the fiber suspends or terminates.
|
|
|
|
*
|
2021-01-04 04:30:43 +01:00
|
|
|
* Must be called within a {@see FiberScheduler}.
|
2020-11-21 07:18:14 +01:00
|
|
|
*
|
|
|
|
* @param mixed $value
|
|
|
|
*
|
|
|
|
* @throw FiberError If the fiber is running or terminated.
|
2020-12-09 18:22:47 +01:00
|
|
|
* @throw Throwable If the fiber callable throws an uncaught exception.
|
2020-11-21 07:18:14 +01:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
2021-01-04 04:30:43 +01:00
|
|
|
* Must be called within a {@see FiberScheduler}.
|
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-12-09 18:22:47 +01:00
|
|
|
* @throw Throwable If the fiber callable throws an uncaught exception.
|
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-12-16 05:17:49 +01:00
|
|
|
/**
|
|
|
|
* @return bool True if the fiber has been started.
|
|
|
|
*/
|
|
|
|
public function isStarted(): bool { }
|
|
|
|
|
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 { }
|
|
|
|
|
|
|
|
/**
|
2020-12-09 18:22:47 +01:00
|
|
|
* Returns the currently executing Fiber instance.
|
|
|
|
*
|
2021-01-04 04:30:43 +01:00
|
|
|
* Cannot be called within {@see FiberScheduler}.
|
2020-12-09 18:22:47 +01:00
|
|
|
*
|
|
|
|
* @return self The currently executing fiber.
|
|
|
|
*
|
2021-01-04 04:30:43 +01:00
|
|
|
* @throws FiberError Thrown if within {@see FiberScheduler}.
|
2020-12-09 18:22:47 +01:00
|
|
|
*/
|
|
|
|
public static function this(): self { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suspend execution of the fiber. The fiber may be resumed with {@see Fiber::resume()} or {@see Fiber::throw()}
|
2021-01-04 04:30:43 +01:00
|
|
|
* within the callback used to create the {@see FiberScheduler} given.
|
2020-11-21 07:18:14 +01:00
|
|
|
*
|
2021-01-04 04:30:43 +01:00
|
|
|
* Cannot be called within a {@see FiberScheduler}.
|
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-12-09 18:22:47 +01:00
|
|
|
* @throws FiberError Thrown if within {@see FiberScheduler::run()}.
|
2020-11-21 07:18:14 +01:00
|
|
|
* @throws Throwable Exception provided to {@see Fiber::throw()}.
|
2020-09-24 18:52:22 +02:00
|
|
|
*/
|
2020-12-09 18:22:47 +01:00
|
|
|
public static function suspend(FiberScheduler $scheduler): mixed { }
|
2020-09-24 18:52:22 +02:00
|
|
|
}
|