new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Cloudflare Workers · Runtime APIs · all subjects

eventsource

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

EventSource server-sent events API definition

EventSource is a server-sent event API that allows a server to push events to a client. The EventSource object connects to a server over HTTP and receives events in a text-based format.

EventSource constructor syntax

EventSource is created with the constructor `new EventSource(url, options)` where url is a USVString representing the URL to connect to, and options is an optional EventSourceInit dictionary containing optional settings.

EventSource fetcher option for Workers bindings

The EventSource constructor accepts a `fetcher` option to use a different fetch implementation, such as one provided by a Cloudflare Workers binding. This is specified as `{ fetcher: env.MYFETCHER }` and is a Cloudflare Workers specific extension. By default, EventSource uses the global `fetch()` function under the covers.

EventSource url property

The `eventSource.url` property is a read-only USVString that returns the URL of the event source.

EventSource readyState property

The `eventSource.readyState` property is a read-only USVString that indicates the state of the connection.

EventSource withCredentials property

The `eventSource.withCredentials` property is a read-only Boolean that indicates whether the EventSource object was instantiated with cross-origin (CORS) credentials set (`true`), or not (`false`).

EventSource close method

The `eventSource.close()` method closes the connection.

EventSource event handlers

EventSource has three event handler properties: `onopen` called when a connection is opened, `onmessage` called when a message is received, and `onerror` called when an error occurs.

EventSource events

EventSource fires three events: `open` fired when the connection is opened, `message` fired when a message is received, and `error` fired when an error occurs.

EventSource.from class method

EventSource.from(readableStream) is a Cloudflare Workers specific extension that creates a new EventSource object from an existing ReadableStream. This instance does not initiate a new connection but instead attaches to the provided stream.

Give your agent this brain