Public Bus constructor. The Handle supplied to this
constructor is assigned as readonly
on the constructed Bus
instance and will be used to determine the mount point of this duplex
stream within the hierarchical structure of streams handled by the
BusHandler.
Readonly
handlePrivate
Readonly
observeThe observed side of this Bus. The Observable assigned to this property is used to fullfil the Subscribable contract and is obtained through the BusHandler.
Private
Readonly
publishThe publishing side of this Bus. The Subject assigned to this property is used to fullfil the Observer contract and is provided to the BusHandler for publishment.
Well-known Symbol.observable
method returning a Subscribable. The
returned Subscribable emits the raw Values observed
by this Bus. By comparison, the implemented subscribe
method of the Subscribable interface dematerializes these
raw Values before passing them through to the Observer.
A Subscribable emitting raw Values.
Subscribe to a raw Bus:
import { Bus } from '@sgrud/bus';
import { from } from 'rxjs';
const bus = new Bus<string, string>('io.github.sgrud.example');
from(bus).subscribe(console.log);
Implemented complete method of the Observer contract. Invoking this method will mark the publishing side of this duplex Bus as completed.
complete a Bus:
import { Bus } from '@sgrud/bus';
const bus = new Bus<string, string>('io.github.sgrud.example');
bus.complete();
Implemented error method of the Observer contract. Invoking
this method will throw the supplied error
on the publishing side
of this duplex Bus.
The error
to publish.
Throw an error through a Bus:
import { Bus } from '@sgrud/bus';
const bus = new Bus<string, string>('io.github.sgrud.example');
bus.error(new Error('example));
Implemented next method of the Observer contract. Invoking this
method will provide any observer of the publishing side of this
duplex Bus with the next value
.
Supplying a Bus with a next value:
import { Bus } from '@sgrud/bus';
const bus = new Bus<string, string>('io.github.sgrud.example');
bus.next('value');
Implemented subscribe method of the Subscribable contract.
Invoking this method while supplying an observer
will subscribe the
supplied observer
to any changes on the observed side of this
duplex Bus.
An Unsubscribable of the ongoing observation.
subscribe to a dematerialized Bus:
import { Bus } from '@sgrud/bus';
const bus = new Bus<string, string>('io.github.sgrud.example');
bus.subscribe({ next: console.log });
Generated using TypeDoc
The Bus class presents an easy way to establish duplex streams. Through the on-construction supplied Handle the mount point of the created duplex streaming Bus within the hierarchical structure of streams handled by the BusHandler is designated. Thereby, all Values emitted by the created Bus originate from streams beneath the supplied Handle and when invoking the next method of the implemented Observer contract, the resulting Value will originate from this supplied Handle.
An instantiated Bus allows for two modes of observation to facilitate simple and complex use cases. The implemented Subscribable contract allows for observation of the dematerialized Values, while the well-known
Symbol.observable
method provides a way to observe the raw Values, including their originating Handles.Example
Using a duplex streaming Bus: