Shut down the publisher
Notifies all subscribers of an error and shuts down the publisher.
the exception which occurred
Allows for subscribing only to values which meet given criteria. Should only be called in conjunction with subscribe. For example
const publisher = new Publisher<number>();
publisher.filter((x) => x < 50).subscribe({
next: (value: number) => {
console.log(value, "is less than 50");
}
})
the predicate determining if subscribers should be notified
Allows for subscribing only to values of a given subtype the published type Should only be called in conjunction with subscribe. For example
type First = "first";
type Second = "second";
type Option = First | Second;
function isFirst(value: Options): value is First { ... }
const publisher = new Publisher<Option>();
publisher.filterType(isFirst).subscribe({
next: (value: First) => {
console.log(value, "is of a subtype of option");
}
})
Attaches a new subscription to the publisher For example
const publisher = new Publisher<number>();
publisher.subscribe({
next: (value: number) => {
console.log(value);
}
})
an object with at least a next method which is called whenever the publisher publishes new data
Class implementing the Publisher-Subscriber pattern. Allows for publishing and subscribing to messages.