wonka
Version:
A fast push & pull stream library for Reason, loosely following the [callbag spec](https://github.com/callbag/callbag)
70 lines (63 loc) • 2.51 kB
JavaScript
;
var Block = require("bs-platform/lib/js/block.js");
var Curry = require("bs-platform/lib/js/curry.js");
var Caml_option = require("bs-platform/lib/js/caml_option.js");
function talkbackPlaceholder(param) {
return /* () */0;
}
function captureTalkback(source, sinkWithTalkback) {
var talkback = /* record */[/* contents */talkbackPlaceholder];
return Curry._1(source, (function (signal) {
if (typeof signal !== "number") {
if (!signal.tag) {
talkback[0] = signal[0];
}
}
return sinkWithTalkback(signal, talkback[0]);
}));
}
function makeTrampoline(sink, f) {
var state = /* record */[
/* exhausted */false,
/* inLoop */false,
/* gotSignal */false
];
return sink(/* Start */Block.__(0, [(function (signal) {
var match = state[/* exhausted */0];
if (signal || match) {
return /* () */0;
} else {
state[/* gotSignal */2] = true;
if (state[/* inLoop */1]) {
return 0;
} else {
var explode = function (_param) {
while(true) {
var match = f();
if (match !== undefined) {
state[/* gotSignal */2] = false;
sink(/* Push */Block.__(1, [Caml_option.valFromOption(match)]));
if (state[/* gotSignal */2]) {
_param = /* () */0;
continue ;
} else {
return 0;
}
} else {
state[/* exhausted */0] = true;
return sink(/* End */0);
}
};
};
state[/* inLoop */1] = true;
explode(/* () */0);
state[/* inLoop */1] = false;
return /* () */0;
}
}
})]));
}
exports.talkbackPlaceholder = talkbackPlaceholder;
exports.captureTalkback = captureTalkback;
exports.makeTrampoline = makeTrampoline;
/* No side effect */