push($callback); } } /** * Unrolls instances of self to avoid blowing up the call stack on resolution. * * @param callable $callback */ public function push(callable $callback) { if ($callback instanceof self) { $this->queue = \array_merge($this->queue, $callback->queue); return; } $this->queue[] = $callback; } /** * Calls each callback in the queue, passing the provided values to the function. * * @param \Throwable|null $exception * @param mixed $value */ public function __invoke($exception, $value) { foreach ($this->queue as $callback) { try { $callback($exception, $value); } catch (\Throwable $exception) { Loop::defer(function () use ($exception) { throw $exception; }); } } } }