1
0
mirror of https://github.com/danog/amp.git synced 2024-12-02 17:37:50 +01:00
amp/stubs/Fiber.php

94 lines
2.8 KiB
PHP
Raw Normal View History

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.
*
* @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.
* @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.
* @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 { }
/**
* Returns the currently executing Fiber instance.
*
2021-01-04 04:30:43 +01:00
* Cannot be called within {@see FiberScheduler}.
*
* @return self The currently executing fiber.
*
2021-01-04 04:30:43 +01:00
* @throws FiberError Thrown if within {@see FiberScheduler}.
*/
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
*
* @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
*/
public static function suspend(FiberScheduler $scheduler): mixed { }
2020-09-24 18:52:22 +02:00
}