Server-Sent Events

Valum provides a middleware for the HTML5 Server-Sent Events protocol to stream notifications over a persistent connection.

The valum-0.3/Valum.ServerSentEvents.stream_events function creates a handling middleware and provide a valum-0.3/Valum.ServerSentEvents.SendEventCallback callback to transmit the actual events.

using Valum;
using Valum.ServerSentEvents;

app.get ("sse", stream_events ((req, send) => {
    send (null, "some data");
var eventSource = new EventSource ("/sse");

eventSource.onmessage = function(message) {
    console.log (; // displays 'some data'

Multi-line messages

Multi-line messages are handled correctly by splitting the data into into multiple data: chunks.

send (null, "some\ndata");
data: some
data: data