wonka
Version:
A fast push & pull stream library for Reason, loosely following the [callbag spec](https://github.com/callbag/callbag)
61 lines (56 loc) • 2.31 kB
JavaScript
;
var Block = require("bs-platform/lib/js/block.js");
var Curry = require("bs-platform/lib/js/curry.js");
var Wonka_helpers = require("../wonka_helpers.js");
function delay(wait) {
return (function (source) {
return (function (sink) {
var state = /* record */[
/* talkback */Wonka_helpers.talkbackPlaceholder,
/* active */0,
/* gotEndSignal */false
];
Curry._1(source, (function (signal) {
var exit = 0;
if (typeof signal === "number" || signal.tag) {
exit = 1;
} else {
state[/* talkback */0] = signal[0];
return /* () */0;
}
if (exit === 1) {
if (state[/* gotEndSignal */2]) {
return /* () */0;
} else {
state[/* active */1] = state[/* active */1] + 1 | 0;
setTimeout((function (param) {
if (state[/* gotEndSignal */2] && state[/* active */1] === 0) {
sink(/* End */0);
} else {
state[/* active */1] = state[/* active */1] - 1 | 0;
}
return sink(signal);
}), wait);
return /* () */0;
}
}
}));
return sink(/* Start */Block.__(0, [(function (signal) {
if (signal) {
state[/* gotEndSignal */2] = true;
if (state[/* active */1] === 0) {
return sink(/* End */0);
} else {
return 0;
}
} else if (state[/* gotEndSignal */2]) {
return /* () */0;
} else {
return state[/* talkback */0](signal);
}
})]));
});
});
}
exports.delay = delay;
/* No side effect */