Events#
This page covers waiting on events and calling back on them. An event is a stream of bool that is true on each firing, as described under Events.
Getting Events#
events-event [events] [MUST]A procedure that returns an event gives the program an event. Waiting on it returns when it fires.
events-event-stream [events] [MUST]The stream of an event is a stream of bool. Its value is false until the event fires, and true after a firing.
Handles#
events-equality [events] [MUST]Copies of an event handle are equal. Events from two calls of one procedure are not.
events-hash [events] [MUST]Copies of an event handle hash equal, in a language that hashes handles.
Callbacks#
events-callback [events, callbacks] [MUST]A callback is called once for each firing after it is added.
events-remove-callback [events, callbacks] [MUST]A removed callback is not called again.
Unseen Firings#
A firing is unseen until a wait on the event returns for it or one of its callbacks is called for it. A callback added after an unseen firing is called for it, which replays the firing. A remove or a close discards an unseen firing, and an end by the server keeps it.
events-callback-after-seen-firing [events, callbacks] [MUST]A callback added once a firing is seen, by a wait or by a callback, is not called for that firing.
events-callback-after-unseen-firing [events, callbacks] [MUST]A callback added after an unseen firing is called once for it. This holds after the server has ended the event too.
events-first-call-on-add [events, callbacks] [SHOULD]Adding a callback after an unseen firing calls the callback before the add returns.
events-one-callback-per-unseen-firing [events, callbacks] [MUST]Of two callbacks added after an unseen firing, only one is called for it.
events-stream-callback-leaves-firing [events, callbacks] [MUST]A callback on the event’s stream leaves the firing unseen, so a callback added to the event later is called for it.
events-removed-callback-leaves-firing [events, callbacks] [MUST]A callback removed before a firing leaves the firing unseen, so a callback added later is called for it.
events-callback-added-during-replay [events, callbacks, concurrency, races] [MUST]Of two callbacks added after an unseen firing, only one is called for it, though the second is added while the firing is replayed to the first.
events-callback-removed-during-add [events, callbacks, concurrency, races] [MUST]A callback added after an unseen firing, and removed before the replay calls it, leaves the firing unseen, so a callback added later is called for it.
events-callback-removed-during-update [events, callbacks, races] [MUST]A callback removed while an update passes a firing to the event’s callbacks leaves the firing unseen, so a callback added later is called for it.
Ending#
events-server-end [events] [MUST]Waiting on an event the server ends returns for an unseen firing first. Later waits raise the stream error.
events-ended-without-firing [events] [MUST]Waiting on an event that ends without firing raises the error that ended it.
events-remove [events] [MUST]Waiting on an event the client removed, through the event or through its stream, raises the stream error, at once. An unseen firing is discarded.
events-drop-last-handle [events, callbacks] [MUST]An event runs while the program holds a handle to it. Callbacks added through a copy of the handle keep running after the copy is dropped. Dropping the last handle removes the event: the server stops sending its firings, and its callbacks are not called again.
events-scoped-removal [events] [SHOULD]An event can be scoped to a block of code, using the scoping construct of the language. Leaving the block removes the event: the server stops sending its firings.
events-wait-after-close [events] [MUST]Waiting on an event after the connection closes raises the connection error.
Waiting#
events-firing-before-wait [events] [MUST]A firing before the first wait is unseen, so the wait returns at once.
events-firings-coalesce [events] [MUST]Several firings before a wait make it return once.
events-repeated-waits [events] [MUST]Repeated waits on a repeating event return once for each firing.
events-wait-timeout [events] [MUST]Waiting with a timeout returns false when the timeout elapses before a firing, and true on a firing.
events-wait-timeout-values [events] [MUST]A zero timeout returns at once, with true when a firing is pending. An infinite timeout waits with no deadline, as a wait without a timeout does. A negative or NaN timeout raises the argument error.
events-two-waiters [events, concurrency] [MUST]Two waits on one event both return when it fires.
events-wake-waiter [events, concurrency] [MUST]A wait on an event ends when the event is removed, the connection closes or the connection fails. The wait raises the stream error, or the connection error, with the reason for a failure.
End Callbacks#
events-end-callback [events, callbacks] [MUST]An end callback is called once when the event ends: by the server, by a remove, or by a close or failure of the connection. The callback receives the error a wait on the event then raises: the error for an event the server ended, the error for a removed stream, or the connection error. An event that ends without firing calls none of its callbacks.