Event
Signature - source.ts#L117
type Event<T> = Push<T> | Throw | End
This is the base construct for distributing values/messages. All things pushed and received to and from Sinks will be events. An event is an object which consists of a type field, which determines the type of the event. There are three types of events: Push, Throw and End events:
A Push event represents the "pushing" of a value to a sink, and has a value field equal to the value the event is carrying.
A Throw represents the "throwing" of an error, and has an error field equal to the error the event is carrying. After a Sink receives an Error event, it will be disposed and will not take any more events.
An End event represents the "end" of a source, and has no additional properties. After a Sink receives an End event, it will be disposed and will not take any more events.
When determining an event's type, you should always use either PushType, ThrowType or EndType directly instead of their constant number values.
Example Usage
const sink = Sink<number>(event => {
console.log(event.type); // Either `PushType`, `ThrowType` or `EndType`.
if (event.type === PushType) {
// In this case event.value this will be of type `number`.
console.log('value:', event.value);
} else if (event.type === ThrowType) {
const error = event.error; // This is of type `unknown`.
console.log('error', event.error);
}
});
sink(Push(2)); // `${PushType}`, value: 2.
sink(Throw(new Error('...'))); // `${ThrowType}`, Error(...).
See Also
EventType
Signature - source.ts#L48
type EventType = PushType | ThrowType | EndType