Public BusHandler constructor. As the BusHandler is a
Singleton class, this constructor is only invoked the first
time it is targeted by the new
operator. Upon this first invocation, the
worker property is assigned an instance of the BusWorker
Thread while using the supplied source
, if any.
Optional
source: stringAn optional Kernel.Module source
.
A ReferenceError when the environment is incompatible.
Static
Private
loaderPrivate static ReplaySubject used as the BusHandler loader. This loader emits once after the BusHandler has been successfully initialized.
Readonly
workerThe worker Thread and main background workhorse. The underlying BusWorker is run inside a Worker context in the background and transparently handles published and observed streams and the aggregation of their values depending on their Bus.Handle, i.e., hierarchy.
Static
[observable]Static Symbol.observable
method returning a Subscribable. The
returned Subscribable mirrors the private loader and is
used for initializations after the BusHandler has been
successfully initialized.
A Subscribable emitting this BusHandler.
Subscribe to the BusHandler:
import { BusHandler } from '@sgrud/bus';
import { from } from 'rxjs';
from(BusHandler).subscribe(console.log);
Invoking this method observes the Observable stream represented
by the supplied handle
. The method will return an Observable
originating from the BusWorker which emits all Bus.Values
published under the supplied handle
. When the observe method is
invoked with 'io.github.sgrud'
, all streams hierarchically beneath this
Bus.Handle, e.g., 'io.github.bus.status'
, will also be emitted by
the returned Observable.
The type of the observed Observable stream.
The Bus.Handle to observe.
An Observable bus for handle
.
observe the 'io.github.sgrud'
stream:
import { BusHandler } from '@sgrud/bus';
const busHandler = new BusHandler();
const handle = 'io.github.sgrud.example';
busHandler.observe(handle).subscribe(console.log);
Invoking this method publishes the supplied Observable stream
under the supplied handle
. This method returns an Observable of
the publishment of the supplied Observable stream
under the
supplied handle
with the BusWorker. When the published
source
Observable completes, the registration within the
BusWorker will automatically self-destruct.
The type of the published Observable stream.
The Bus.Handle to publish under.
The Observable stream
for handle
.
An Observable of the stream
publishment.
publish a stream under 'io.github.sgrud.example'
:
import { BusHandler } from '@sgrud/bus';
import { of } from 'rxjs';
const busHandler = new BusHandler();
const handle = 'io.github.sgrud.example';
const stream = of('published');
busHandler.publish(handle, stream).subscribe();
Invoking this method uplinks the supplied handle
to the supplied
url
by establishing a WebSocket connection between the endpoint
behind the supplied url
and the BusWorker. This method returns an
Observable of the uplink Subscription which can be used
to cancel the uplink. When the uplinked WebSocket is closed
or throws an error, it is automatically cleaned up and unsubscribed from.
The Bus.Handle to uplink.
The endpoint url
to establish an uplink to.
An Observable of the uplink Subscription.
uplink the 'io.github.sgrud.uplink'
Bus.Handle:
import { BusHandler } from '@sgrud/bus';
const busHandler = new BusHandler();
const handle = 'io.github.sgrud.example';
const url = 'https://example.com/websocket';
const uplink = busHandler.uplink(handle, url).subscribe();
Generated using TypeDoc
The BusHandler implements and orchestrates the establishment, transferral and deconstruction of any number of Observable streams. It operates in conjunction with the BusWorker Thread which is run in the background. To designate and organize different Observable streams, the string literal helper type Bus.Handle is employed. As an example, let the following hierarchical structure be given:
Depending on the Bus.Handle, one may observe all established streams beneath the root
io.github.sgrud
Bus.Handle or only one specific stream, e.g.,io.github.sgrud.core.kernel
. The Observable returned from the observe method will emit all Bus.Values originating from all streams beneath the root Bus.Handle in the first case, or only Bus.Values from one stream, in the second case.Decorator
Singleton
See
BusWorker