UNPKG

wonka

Version:

A fast push & pull stream library for Reason, loosely following the [callbag spec](https://github.com/callbag/callbag)

53 lines (49 loc) 1.44 kB
'use strict'; var Block = require("bs-platform/lib/js/block.js"); function makeSubject(param) { var state = /* record */[ /* sinks */new Array(), /* ended */false ]; var source = function (sink) { state[/* sinks */0] = state[/* sinks */0].concat(sink); return sink(/* Start */Block.__(0, [(function (signal) { if (signal === /* Close */1) { state[/* sinks */0] = state[/* sinks */0].filter((function (x) { return x !== sink; })); return /* () */0; } else { return 0; } })])); }; var next = function (value) { if (state[/* ended */1]) { return 0; } else { state[/* sinks */0].forEach((function (sink) { return sink(/* Push */Block.__(1, [value])); })); return /* () */0; } }; var complete = function (param) { if (state[/* ended */1]) { return 0; } else { state[/* ended */1] = true; state[/* sinks */0].forEach((function (sink) { return sink(/* End */0); })); return /* () */0; } }; return /* record */[ /* source */source, /* next */next, /* complete */complete ]; } exports.makeSubject = makeSubject; /* No side effect */