From 80ea42bdcfc4176f78162d5e3cbcad9c4cc20761 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Tue, 15 Dec 2020 22:17:49 -0600 Subject: [PATCH] Update for Fiber constructor change --- lib/functions.php | 4 ++-- stubs/Fiber.php | 16 +++++++--------- stubs/ReflectionFiber.php | 9 +++++++-- stubs/ReflectionFiberScheduler.php | 4 +--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index 4c983f6..08a9938 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -53,7 +53,7 @@ namespace Amp { $placeholder = new Internal\Placeholder; - $fiber = \Fiber::create(static function () use ($placeholder, $callback, $args): void { + $fiber = new \Fiber(static function () use ($placeholder, $callback, $args): void { try { $placeholder->resolve($callback(...$args)); } catch (\Throwable $exception) { @@ -90,7 +90,7 @@ namespace Amp */ function defer(callable $callback, mixed ...$args): void { - $fiber = \Fiber::create(static function () use ($callback, $args): void { + $fiber = new \Fiber(static function () use ($callback, $args): void { try { $callback(...$args); } catch (\Throwable $exception) { diff --git a/stubs/Fiber.php b/stubs/Fiber.php index ef10f38..a4a016e 100644 --- a/stubs/Fiber.php +++ b/stubs/Fiber.php @@ -3,11 +3,9 @@ final class Fiber { /** - * @param callable $callback Function to invoke when running the fiber. - * - * @return self A new Fiber that has not been started. + * @param callable $callback Function to invoke when starting the fiber. */ - public static function create(callable $callback): self { } + public function __construct(callable $callback) { } /** * Starts execution of the fiber. Returns when the fiber suspends or terminates. @@ -47,6 +45,11 @@ final class Fiber */ public function throw(Throwable $exception): void { } + /** + * @return bool True if the fiber has been started. + */ + public function isStarted(): bool { } + /** * @return bool True if the fiber is suspended. */ @@ -87,9 +90,4 @@ final class Fiber * @throws Throwable Exception provided to {@see Fiber::throw()}. */ public static function suspend(FiberScheduler $scheduler): mixed { } - - /** - * Private constructor to force use of {@see create()}. - */ - private function __construct() { } } diff --git a/stubs/ReflectionFiber.php b/stubs/ReflectionFiber.php index ea6bc0f..4fc76dd 100644 --- a/stubs/ReflectionFiber.php +++ b/stubs/ReflectionFiber.php @@ -27,12 +27,17 @@ class ReflectionFiber public function getTrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT): array { } /** - * @return bool True if the fiber is currently suspended, false otherwise. + * @return bool True if the fiber has been started. + */ + public function isStarted(): bool { } + + /** + * @return bool True if the fiber is currently suspended. */ public function isSuspended(): bool { } /** - * @return bool True if the fiber is currently running, false otherwise. + * @return bool True if the fiber is currently running. */ public function isRunning(): bool { } diff --git a/stubs/ReflectionFiberScheduler.php b/stubs/ReflectionFiberScheduler.php index 0492565..ec45864 100644 --- a/stubs/ReflectionFiberScheduler.php +++ b/stubs/ReflectionFiberScheduler.php @@ -4,13 +4,11 @@ class ReflectionFiberScheduler extends ReflectionFiber { /** * @param FiberScheduler $scheduler - * - * @throws FiberError If the {@see FiberScheduler} has not been used to suspend a fiber. */ public function __construct(FiberScheduler $scheduler) { } /** * @return FiberScheduler The instance used to create the fiber. */ - public function getFiberScheduler(): FiberScheduler { } + public function getScheduler(): FiberScheduler { } }