Skip to content

Commit 690d980

Browse files
authored
Cork the timer writes in ServerSentEvents.js example (#1307)
The interval callback writes to the response outside of any uWS callback, so every event printed "Warning: uWS.HttpResponse writes must be made from within a corked callback". Wrap the write in res.cork(), the same way VideoStreamer.js was fixed.
1 parent 95b1a7e commit 690d980

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎examples/ServerSentEvents.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ const app = uWS./*SSL*/App({
3131
res.writeStatus('200 OK')
3232

3333
let intervalRef = setInterval(() => {
34-
res.write(serializeData({ message: 'Hello world!' }))
34+
/* Writes made outside of a uWS callback, like from a timer, must be corked */
35+
res.cork(() => {
36+
res.write(serializeData({ message: 'Hello world!' }))
37+
})
3538
}, 1000)
3639

3740
res.onAborted(() => {

0 commit comments

Comments
 (0)