wonka
Version:
A fast push & pull stream library for Reason, loosely following the [callbag spec](https://github.com/callbag/callbag)
73 lines (64 loc) • 2.45 kB
JavaScript
import * as Block from "bs-platform/lib/es6/block.js";
import * as Curry from "bs-platform/lib/es6/curry.js";
import * as Caml_option from "bs-platform/lib/es6/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;
}
}
})]));
}
export {
talkbackPlaceholder ,
captureTalkback ,
makeTrampoline ,
}
/* No side effect */