Control stream lifetime with Locking
mainBy default, streams are locked server-side (kept alive indefinitely). You can control this using the lock object (a Writable<bool>) provided to the start function. Setting lock.set(false) closes the stream.
Important: Do not attempt to emit messages after calling lock.set(false), as emit will return an error.
import { produce } from 'sveltekit-sse'
export function POST() {
return produce(function start({ emit, lock }) {
emit('message', 'hello world')
setTimeout(function unlock() {
lock.set(false)
}, 2000)
})
}import { produce } from 'sveltekit-sse'
export function POST() {
return produce(function start({ emit, lock }) {
emit('message', 'hello world')
setTimeout(function unlock() {
lock.set(false)
}, 2000)
})
}