1<?php 2 3final class Fiber 4{ 5 /** 6 * @param callable $callback Function to invoke when starting the fiber. 7 */ 8 public function __construct(callable $callback) {} 9 10 /** 11 * Starts execution of the fiber. Returns when the fiber suspends or terminates. 12 * 13 * @param mixed ...$args Arguments passed to fiber function. 14 * 15 * @return mixed Value from the first suspension point or NULL if the fiber returns. 16 * 17 * @throw FiberError If the fiber has already been started. 18 * @throw Throwable If the fiber callable throws an uncaught exception. 19 */ 20 public function start(mixed ...$args): mixed {} 21 22 /** 23 * Resumes the fiber, returning the given value from {@see Fiber::suspend()}. 24 * Returns when the fiber suspends or terminates. 25 * 26 * @param mixed $value 27 * 28 * @return mixed Value from the next suspension point or NULL if the fiber returns. 29 * 30 * @throw FiberError If the fiber has not started, is running, or has terminated. 31 * @throw Throwable If the fiber callable throws an uncaught exception. 32 */ 33 public function resume(mixed $value = null): mixed {} 34 35 /** 36 * Throws the given exception into the fiber from {@see Fiber::suspend()}. 37 * Returns when the fiber suspends or terminates. 38 * 39 * @param Throwable $exception 40 * 41 * @return mixed Value from the next suspension point or NULL if the fiber returns. 42 * 43 * @throw FiberError If the fiber has not started, is running, or has terminated. 44 * @throw Throwable If the fiber callable throws an uncaught exception. 45 */ 46 public function throw(Throwable $exception): mixed {} 47 48 /** 49 * @return bool True if the fiber has been started. 50 */ 51 public function isStarted(): bool {} 52 53 /** 54 * @return bool True if the fiber is suspended. 55 */ 56 public function isSuspended(): bool {} 57 58 /** 59 * @return bool True if the fiber is currently running. 60 */ 61 public function isRunning(): bool {} 62 63 /** 64 * @return bool True if the fiber has completed execution (returned or threw). 65 */ 66 public function isTerminated(): bool {} 67 68 /** 69 * @return mixed Return value of the fiber callback. NULL is returned if the fiber does not have a return statement. 70 * 71 * @throws FiberError If the fiber has not terminated or the fiber threw an exception. 72 */ 73 public function getReturn(): mixed {} 74 75 /** 76 * @return self|null Returns the currently executing fiber instance or NULL if in {main}. 77 */ 78 public static function getCurrent(): ?self {} 79 80 /** 81 * Suspend execution of the fiber. The fiber may be resumed with {@see Fiber::resume()} or {@see Fiber::throw()}. 82 * 83 * Cannot be called from {main}. 84 * 85 * @param mixed $value Value to return from {@see Fiber::resume()} or {@see Fiber::throw()}. 86 * 87 * @return mixed Value provided to {@see Fiber::resume()}. 88 * 89 * @throws FiberError Thrown if not within a fiber (i.e., if called from {main}). 90 * @throws Throwable Exception provided to {@see Fiber::throw()}. 91 */ 92 public static function suspend(mixed $value = null): mixed {} 93} 94