Skip to main content

\Co\signal

###API

namespace Co;

function onSignal(int $signalCode,Closure $closure): string;

Parameter description​

ParametersTypeDescription
$signalCodeintsignal code
$closureClosureSignal handler, runs in event context

Closure parameters​

ParametersTypeDescription
$signalCodeintsignal code

Return value​

Returns the unique identifier of the event, allowing the event to be canceled using the \Co\cancel method

Overview​

Ripple allows you to listen to system signals through the onSignal method and execute the specified closure function when the signal is triggered.

Basic usage​

\Co\onSignal(SIGINT, function () {
echo 'signal received';
exit(0);
});

Notes​

After registering any signal handler, if the signal handler is not canceled correctly, \Co\wait will think that there are unfinished events and will wait until all events are completed.