mirror of
https://github.com/danog/amp.git
synced 2025-01-22 21:31:18 +01:00
Avoid unnecessary promise object
This commit is contained in:
parent
74a24b36df
commit
b95048abd9
@ -77,15 +77,24 @@ namespace Amp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the given callback in a new green thread using {@see async()}, forwarding any exceptions thrown to
|
* Executes the given callback in a new green thread similar to {@see async()}, except instead of returning a
|
||||||
* the event loop error handler using {@see Promise\rethrow()}.
|
* promise, any exceptions thrown are forwarded to the event loop error handler. The return value of the function
|
||||||
|
* is discarded.
|
||||||
*
|
*
|
||||||
* @param callable(mixed ...$args):void $callback
|
* @param callable(mixed ...$args):void $callback
|
||||||
* @param mixed ...$args
|
* @param mixed ...$args
|
||||||
*/
|
*/
|
||||||
function defer(callable $callback, mixed ...$args): void
|
function defer(callable $callback, mixed ...$args): void
|
||||||
{
|
{
|
||||||
Promise\rethrow(async($callback, ...$args));
|
$fiber = \Fiber::create(static function () use ($callback, $args): void {
|
||||||
|
try {
|
||||||
|
$callback(...$args);
|
||||||
|
} catch (\Throwable $exception) {
|
||||||
|
Loop::defer(static fn() => throw $exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Loop::defer(fn() => $fiber->start());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user