/** * Returned Generators are run as coroutines. Failures of the coroutine are forwarded to the loop error handler. * * @see \Interop\Async\Loop::setErrorHandler() * * @param callable $callback */ function setErrorHandler(callable $callback) { Loop::setErrorHandler(function ($exception) use($callback) { $result = $callback($exception); if ($result instanceof \Generator) { rethrow(new Coroutine($result)); } }); }