UNPKG

2.09 kBTypeScriptView Raw
1import { EventStream } from "./observable";
2import Observable from "./observable";
3import { EventSink, Unsub } from "./types";
4import { Reply } from "./reply";
5interface Subscription<V> {
6 input: Observable<V>;
7 unsub: Unsub | undefined;
8}
9/**
10 An [`EventStream`](eventstream.html) that allows you to [`push`](#push) values into the stream.
11
12 It also allows plugging other streams into the Bus, as inputs. The Bus practically
13 merges all plugged-in streams and the values pushed using the [`push`](#push)
14 method.
15 */
16export default class Bus<V> extends EventStream<V> {
17 /** @hidden */
18 sink?: EventSink<V>;
19 /** @hidden */
20 pushing: boolean;
21 /** @hidden */
22 pushQueue?: V[];
23 /** @hidden */
24 ended: boolean;
25 /** @hidden */
26 subscriptions: Subscription<V>[];
27 constructor();
28 /**
29 Plugs the given stream as an input to the Bus. All events from
30 the given stream will be delivered to the subscribers of the Bus.
31 Returns a function that can be used to unplug the same stream.
32
33 The plug method practically allows you to merge in other streams after
34 the creation of the Bus.
35
36 * @returns a function that can be called to "unplug" the source from Bus.
37 */
38 plug<V2 extends V>(input: Observable<V2>): (() => void) | undefined;
39 /**
40 Ends the stream. Sends an [End](end.html) event to all subscribers.
41 After this call, there'll be no more events to the subscribers.
42 Also, the [`push`](#push), [`error`](#error) and [`plug`](#plug) methods have no effect.
43 */
44 end(): Reply;
45 /**
46 * Pushes a new value to the stream.
47 */
48 push(value: V): Reply;
49 /**
50 * Pushes an error to this stream.
51 */
52 error(error: any): Reply;
53 /** @hidden */
54 unsubAll(): void;
55 /** @hidden */
56 subscribeAll(newSink: EventSink<V>): () => void;
57 /** @hidden */
58 guardedSink(input: Observable<V>): EventSink<V>;
59 /** @hidden */
60 subscribeInput(subscription: Subscription<V>): Unsub;
61 /** @hidden */
62 unsubscribeInput(input: Observable<any>): void;
63}
64export {};