You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I adapted the last lines of the example in the README to Windows, because SIGINT (pcntl) is not available there.
I converted it this way making use of sapi_windows_set_ctrl_handler($callback) to intercept CTRL+C whilst the script is running in a terminal.
EventLoop::defer( function () use ( $logger, $server ): void {
$logger->info( 'OS: Windows' );
// async wait for server admin to hit CTRL+Csapi_windows_set_ctrl_handler( function ( int$event ) use ( $logger, $server ) {
$logger->info( sprintf( "Received signal, stopping HTTP server" ) );
$server->stop();
} );
} );
EventLoop::run();
The callback is fired, the server says is stopping, but an assertion fires afterward, I don't think it successfully stops:
The problem is that sapi_windows_set_ctrl_handler works via the internal interrupt mechanism and will cause execution of its closure within the event loop fiber itself (where fiber switches are not allowed).
I haven't tested it, but wrapping the contents of the closure inside EventLoop::queue (microtask) may work, i.e.:
sapi_windows_set_ctrl_handler( function ( int $event ) use ( $logger, $server ) {
EventLoop::queue(function() use ($looger, $server) {
$logger->info( sprintf( "Received signal, stopping HTTP server" ) );
$server->stop();
});
} );
Thank you for the ideas, I tried I think almost all combinations of closures/scopes but the error persists, maybe it hasn't solution with the actual state of the library, maybe I'll drop an issue in the github of Revolt.
I adapted the last lines of the example in the README to Windows, because SIGINT (pcntl) is not available there.
I converted it this way making use of sapi_windows_set_ctrl_handler($callback) to intercept CTRL+C whilst the script is running in a terminal.
The callback is fired, the server says is stopping, but an assertion fires afterward, I don't think it successfully stops:
This is not breaking the script atm but maybe it's worth taking a look into it?
The text was updated successfully, but these errors were encountered: