Skip to content

Commit

Permalink
refactor: use EventEmitter.once where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Oct 27, 2021
1 parent 71e9586 commit cb16588
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/use/fastify-websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export function makeHandler<

// fastify-websocket uses the WebSocket.createWebSocketStream,
// therefore errors get emitted on both the connection and the socket
connection.on('error', handleEmittedError);
socket.on('error', handleEmittedError);
connection.once('error', handleEmittedError);
socket.once('error', handleEmittedError);

// keep alive through ping-pong messages
let pongWait: NodeJS.Timeout | null = null;
Expand Down
4 changes: 2 additions & 2 deletions src/use/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function useServer<
const isProd = process.env.NODE_ENV === 'production';
const server = makeServer(options);

ws.on('error', (err) => {
ws.once('error', (err) => {
console.error(
'Internal error emitted on the WebSocket server. ' +
'Please check your implementation.',
Expand Down Expand Up @@ -80,7 +80,7 @@ export function useServer<
});

ws.on('connection', (socket, request) => {
socket.on('error', (err) => {
socket.once('error', (err) => {
console.error(
'Internal error emitted on a WebSocket socket. ' +
'Please check your implementation.',
Expand Down

0 comments on commit cb16588

Please sign in to comment.