moleculer-web-uws
Version:
The `moleculer-web-uws` is a fast API gateway service for Moleculer based on µWebSockets.js server. Use it to publish your services over HTTP and WebSockets.
16 lines (11 loc) • 467 B
JavaScript
function handleDisconnect(connectionContext, options = {}) {
const { exitCode = 1000, reason } = options;
const { cancelKeepAlive, socket, isDisconnecting } = connectionContext;
if (isDisconnecting) return
connectionContext.isDisconnecting = true;
// check if isClosing & if isClosing bail
cancelKeepAlive && clearInterval(cancelKeepAlive);
if (socket.done) return
socket.end(exitCode, reason);
}
module.exports = handleDisconnect;