Sse

class Sse

Wrapper around the Request object for handeling Server Sent Event replies

tx: cosock.channel
static new(res, keepalive)

Wrap a Response in a new server sent event handle. This will spawn

a cosock task that will manage the keepalive messages along with any the sending of any intentional events or data

if keepalive is a number it will be used to determine the wait between events otherwise if truthy, it will default to set to 15 seconds

Note: This requires that the server is configured with the async property set to true

Parameters
  • res (Response) – The response to wrap

  • keepalive (boolean or integer) – if a number the maximum number of seconds to wait between events to send an empty comment

Returns

A handle to the server sent event task

Return type

Sse

send(ev)

Send an event

Parameters

ev (Event) –

Return type

integer or nil

Return type

str

class Event

A single Server Sent Event, this implements a builder pattern, so after calling new all other methods return the instance being updated.

_id: str or nil
_comment: str or nil
_data: str or nil
_retry: number or nil
static new()

Constructor of an empty event

Return type

Event

comment(comment)

Set the comment for this event

Parameters

comment (str) –

Return type

Event

event(event)

Set the event name for this event

Parameters

event (str) –

Return type

Event

id(id)

Set the id for this event

Parameters

id (str or number) –

Return type

Event

data(data)

Set the data for this event

Parameters

data (str) –

Return type

Event

retry(retry)

Set the retry for this event

Parameters

retry (str or number) –

Return type

Event

to_string()

Serialize this event into the sse format

Return type

any