1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2025-12-14 10:35:07 +00:00

Add experimental update stream

This commit is contained in:
Cadence Ember
2020-05-22 03:44:52 +12:00
parent 49575dc8a1
commit f798bd158d
3 changed files with 33 additions and 3 deletions

View File

@@ -0,0 +1,30 @@
const {Readable} = require("stream")
const streams = new Set()
setInterval((new (function() {
const payload = `:keepalive ${Date.now()}\n\n`
for (const stream of streams.values()) {
stream.push(payload)
}
})).constructor, 50000)
module.exports = [
{
route: "/api/update_stream", methods: ["GET"], code: async () => {
const stream = new Readable({
read: function() {},
destroy: function() {
streams.delete(stream)
}
})
streams.add(stream)
return {
statusCode: 200,
contentType: "text/event-stream",
stream
}
}
}
]