Menu

Reference / Async

shutdownOn()

function
function shutdownOn(int ...$signals): void

Graceful shutdown: on any of $signals, cancel the root scope.

Async\async(function () {
    Async\shutdownOn(SIGTERM, SIGINT);
    serveForever();                 // unwinds cleanly on the signal
});

This is about scopes, not about signals: everything else follows from cancellation already being structured. The accept loop and every live connection get CancelledException at their next suspend point, each scope joins its children, shield() covers a final flush, and async() returns normally, because a root cancellation is a shutdown, not a failure. The handler is installed with pcntl_signal(); plain pcntl_signal() also works inside async(). Process control (fork, workers, supervision) lives under Process\, not here.

Parameters

...$signals int
the signal numbers, e.g. SIGTERM

See also: dumpOn, shield

View source