Method
phasync::shielded
Run $fn out of every cancellation's reach: phasync::cancel(), Frame::cancel(), and phasync::shutdown() don't cut its waits short. A cancellation that comes meanwhile applies at the coroutine's first wait after $fn returns. For infrastructure that must finish what it started, such as a server ending a protocol cleanly while the application's coroutines stop; application code rarely needs it.
Description#
public static phasync::shielded(
Closure $fn
): mixedA finally block's own wait is not shielded by default: the cancellation is sticky, so it
throws again there too. When that is what ends up terminating the coroutine, phasync warns
(E_USER_WARNING) that cleanup was cut short -- wrap the wait in shielded() instead.
Parameters#
- $fn Closure
Return values#
What $fn returns mixed
Errors / Exceptions#
| Exception | When |
|---|---|
LogicException | Outside a coroutine |
Examples#
phasync::shielded(function () use ($socket) {
fwrite($socket, $goodbye); // still sent during a shutdown
phasync::writable($socket, 1.0);
});