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

93 lines
2.9 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.
*
* @param mixed ...$args Arguments passed to fiber function.
*
2021-02-12 06:02:31 +01:00
* @return mixed Value from the first suspension point.
*
* @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
*/
2021-02-12 06:02:31 +01:00
public function start(mixed ...$args): mixed { }
2020-11-21 07:18:14 +01:00
/**
* Resumes the fiber, returning the given value from {@see Fiber::suspend()}.
* Returns when the fiber suspends or terminates.
*
* @param mixed $value
*
2021-02-12 06:02:31 +01:00
* @return mixed Value from the next suspension point or NULL if the fiber terminates.
*
2020-11-21 07:18:14 +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
*/
2021-02-12 06:02:31 +01:00
public function resume(mixed $value = null): mixed { }
2020-11-21 07:18:14 +01:00
/**
* Throws the given exception into the fiber from {@see Fiber::suspend()}.
* Returns when the fiber suspends or terminates.
*
* @param Throwable $exception
*
2021-02-12 06:02:31 +01:00
* @return mixed Value from the next suspension point or NULL if the fiber terminates.
*
2020-11-21 07:18:14 +01:00
* @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
*/
2021-02-12 06:02:31 +01:00
public function throw(Throwable $exception): mixed { }
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 { }
/**
2021-02-12 06:02:31 +01:00
* @return mixed Return value of the fiber callback.
*
2021-02-12 06:02:31 +01:00
* @throws FiberError If the fiber has not terminated or did not return a value.
*/
public function getReturn(): mixed { }
/**
* @return self|null Returns the currently executing fiber instance or NULL if in {main}.
*/
2021-02-12 06:02:31 +01:00
public static function this(): ?self { }
/**
2021-02-12 06:02:31 +01:00
* Suspend execution of the fiber. The fiber may be resumed with {@see Fiber::resume()} or {@see Fiber::throw()}.
2020-11-21 07:18:14 +01:00
*
2021-02-12 06:02:31 +01:00
* Cannot be called from {main}.
2020-09-24 18:52:22 +02:00
*
2021-02-12 06:02:31 +01:00
* @param mixed $value Value to return from {@see Fiber::resume()} or {@see Fiber::throw()}.
2020-09-24 18:52:22 +02:00
*
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 Throwable Exception provided to {@see Fiber::throw()}.
2020-09-24 18:52:22 +02:00
*/
2021-02-12 06:02:31 +01:00
public static function suspend(mixed $value = null): mixed { }
2020-09-24 18:52:22 +02:00
}