How to exit gracefully from a Vibe.d program using also a Websocket after Ctrl+C?

91 Views Asked by At

Adding as usual where it applies:

scope (exit)
{
    listener.stopListening();
}

is not sufficient to close a vibe.d program gracefully by means of Ctrl+C when it also make use of Websocket implemented like so:

routes.get("/ws", handleWebSockets(&handleWebSocketConnection));

routes being an instance of URLRouter and the related handler looks like so

void handleWebSocketConnection(scope WebSocket socket)
{
    ...

    while (true) {
        ...

        if (!socket.connected) break;

        ...

        socket.send("xxxx");
    }

    ...
}

0

There are 0 best solutions below