diff --git a/examples/VideoStreamer.js b/examples/VideoStreamer.js index 6f8a00f..a4bf5fa 100644 --- a/examples/VideoStreamer.js +++ b/examples/VideoStreamer.js @@ -42,16 +42,16 @@ function pipeStreamOverResponse(res, readStream, totalSize) { } return false; }); - - /* Register async abortion handlers */ - res.onAborted(() => { - console.log('Res is no longer valid!'); - readStream.destroy(); - }); } }).on('end', () => { /* Todo: handle errors of the stream, probably good to simply close the response */ }); + + /* If you plan to asyncronously respond later on, you MUST listen to onAborted BEFORE returning */ + res.onAborted(() => { + console.log('Res is no longer valid!'); + readStream.destroy(); + }); } /* Yes, you can easily swap to SSL streaming by uncommenting here */