diff --git a/src/Internal/FulfilledPromise.php b/src/Internal/FulfilledPromise.php index 78fadf31..1098201d 100644 --- a/src/Internal/FulfilledPromise.php +++ b/src/Internal/FulfilledPromise.php @@ -4,7 +4,6 @@ use React\Promise\Promise; use React\Promise\PromiseInterface; -use function React\Promise\enqueue; use function React\Promise\resolve; /** @@ -30,13 +29,11 @@ public function then(callable $onFulfilled = null, callable $onRejected = null): } return new Promise(function (callable $resolve, callable $reject) use ($onFulfilled): void { - enqueue(function () use ($resolve, $reject, $onFulfilled): void { - try { - $resolve($onFulfilled($this->value)); - } catch (\Throwable $exception) { - $reject($exception); - } - }); + try { + $resolve($onFulfilled($this->value)); + } catch (\Throwable $exception) { + $reject($exception); + } }); } diff --git a/src/Internal/Queue.php b/src/Internal/Queue.php deleted file mode 100644 index 70f85817..00000000 --- a/src/Internal/Queue.php +++ /dev/null @@ -1,30 +0,0 @@ -queue, $task)) { - $this->drain(); - } - } - - private function drain(): void - { - for ($i = \key($this->queue); isset($this->queue[$i]); $i++) { - $task = $this->queue[$i]; - unset($this->queue[$i]); - - $task(); - } - - $this->queue = []; - } -} diff --git a/src/Internal/RejectedPromise.php b/src/Internal/RejectedPromise.php index e5565989..aa126056 100644 --- a/src/Internal/RejectedPromise.php +++ b/src/Internal/RejectedPromise.php @@ -5,7 +5,6 @@ use React\Promise\Promise; use React\Promise\PromiseInterface; use function React\Promise\_checkTypehint; -use function React\Promise\enqueue; use function React\Promise\resolve; /** @@ -27,13 +26,11 @@ public function then(callable $onFulfilled = null, callable $onRejected = null): } return new Promise(function (callable $resolve, callable $reject) use ($onRejected): void { - enqueue(function () use ($resolve, $reject, $onRejected): void { - try { - $resolve($onRejected($this->reason)); - } catch (\Throwable $exception) { - $reject($exception); - } - }); + try { + $resolve($onRejected($this->reason)); + } catch (\Throwable $exception) { + $reject($exception); + } }); } diff --git a/src/functions.php b/src/functions.php index 7517d6a2..b8eac495 100644 --- a/src/functions.php +++ b/src/functions.php @@ -205,20 +205,6 @@ function (\Throwable $reason) use ($i, &$reasons, &$toReject, $reject, &$continu }, $cancellationQueue); } -/** - * @internal - */ -function enqueue(callable $task): void -{ - static $queue; - - if (!$queue) { - $queue = new Internal\Queue(); - } - - $queue->enqueue($task); -} - /** * @internal */ diff --git a/tests/Internal/QueueTest.php b/tests/Internal/QueueTest.php deleted file mode 100644 index 51ffedc1..00000000 --- a/tests/Internal/QueueTest.php +++ /dev/null @@ -1,70 +0,0 @@ -enqueue($this->expectCallableOnce()); - $queue->enqueue($this->expectCallableOnce()); - } - - /** @test */ - public function executesNestedEnqueuedTasks() - { - $queue = new Queue(); - - $nested = $this->expectCallableOnce(); - - $task = function () use ($queue, $nested) { - $queue->enqueue($nested); - }; - - $queue->enqueue($task); - } - - /** - * @test - * @requires PHP 8.1 - */ - public function executesFollowingTasksIfPriorTaskSuspendsFiber() - { - $queue = new Queue(); - - $fiber = new \Fiber(function () use ($queue) { - $queue->enqueue(function () { - \Fiber::suspend(2); - }); - return 1; - }); - - $ret = $fiber->start(); - $this->assertEquals(2, $ret); - - $queue->enqueue($this->expectCallableOnce()); - } - - /** - * @test - */ - public function rethrowsExceptionsThrownFromTasks() - { - $this->expectException(Exception::class); - $this->expectExceptionMessage('test'); - $mock = $this->createCallableMock(); - $mock - ->expects(self::once()) - ->method('__invoke') - ->will(self::throwException(new Exception('test'))); - - $queue = new Queue(); - $queue->enqueue($mock); - } -}