1/* A sink has the signature: `signalT('a) => unit`
2 * A source thus has the signature: `sink => unit`, or `(signalT('a) => unit) => unit`
3 *
4 * Effectively a sink is a callback receiving signals as its first argument.
5 * - Start(talkback) will be carrying a talkback using which the sink can attempt
6 * to pull values (Pull) or request the source to end its stream (End)
7 * - Push(payload) carries a value that the source sends to the sink.
8 * This can happen at any time, since a source can be both pullable or
9 * merely listenable.
10 * - End signifies the end of the source stream, be it because of a talkback (End)
11 * or because the source is exhausted.
12 *
13 * In detail, a talkback is simply a callback that receives a talkback signal as
14 * its first argument. It's thus typically anonymously created by the source.
15 *
16 * A source is a factory that accepts a sink. Calling a source with a sink will
17 * instantiate and initiate the source's stream, after which the source sends the sink
18 * a talkback (Start(talkback)). This is called the "handshake".
19 *
20 * Typically an operator factory won't call the source with a sink it receives
21 * immediately鈥攂ecause this would cause the operator to simply be a noop鈥攂ut instead
22 * it will create an intermediate sink with the same signature to perform its own
23 * logic.
24 *
25 * At that point the operator can for instance intercept the talkback for its own
26 * purposes, or call the actual sink as it sees fit.
27 */
28
29type talkbackT =
30 | Pull
31 | Close;
32
33type signalT('a) =
34 | Start((.talkbackT) => unit)
35 | Push('a)
36 | End;
37
38type sinkT('a) = (.signalT('a)) => unit;
39type sourceT('a) = sinkT('a) => unit;
40
41type teardownT = (.unit) => unit;
42
43type subscriptionT = {
44 unsubscribe: unit => unit
45};
46
47type observerT('a) = {
48 next: 'a => unit,
49 complete: unit => unit
50};
51
52type subjectT('a) = {
53 source: sourceT('a),
54 next: 'a => unit,
55 complete: unit => unit
56};
57
58/* Sinks and sources need to explicitly be their own callbacks;
59 * This means that currying needs to be forced for Bucklescript
60 * not to optimise them away
61 */
62external curry: 'a => 'a = "%identity";