Skip to content

Commit

Permalink
fix(sse_handler_middleware): also stop handshakes when the server clo…
Browse files Browse the repository at this point in the history
…ses the connection
  • Loading branch information
toverux committed May 31, 2017
1 parent df6c169 commit 06e0722
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/sse_handler_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export function sseHandler(options: Partial<ISseMiddlewareOptions> = {}): Handle
res.write(': sse-start\n');

//=> Regularly send keep-alive SSE comments, clear interval on socket close
const keepAliveTimer = setInterval(() => {
res.write(': sse-keep-alive\n');
}, keepAliveInterval);
const keepAliveTimer = setInterval(() => res.write(': sse-keep-alive\n'), keepAliveInterval);

//=> When the connection gets closed (close=client, finish=server), stop the handshake timer
res.once('close', () => clearInterval(keepAliveTimer));
res.once('finish', () => clearInterval(keepAliveTimer));

//=> Done
next();
Expand Down

0 comments on commit 06e0722

Please sign in to comment.