You can use EventSource
to get stream from server until .close()
is called at Worker
, or message is passed to Worker
signalling Worker
to call .close()
.
const es = new EventSource("/path/to/server");
es.addEventListener("open", function(event) {
console.log("event source open")
});
es.addEventListener("message", function(event) {
// do stuff with `event.data`
console.log(event.data);
});
es.addEventListener("error", function(event) {
console.log("event source error", event)
});
button.addEventListener("click", function() {
es.close();
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…