wonka
Version:
A fast push & pull stream library for Reason, loosely following the [callbag spec](https://github.com/callbag/callbag)
67 lines (63 loc) • 2.66 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 sample(notifier) {
return (function (source) {
return (function (sink) {
var state = /* record */[
/* ended */false,
/* value */undefined,
/* sourceTalkback */(function (param) {
return /* () */0;
}),
/* notifierTalkback */(function (param) {
return /* () */0;
})
];
Curry._1(source, (function (signal) {
if (typeof signal === "number") {
state[/* ended */0] = true;
state[/* notifierTalkback */3](/* Close */1);
return sink(/* End */0);
} else if (signal.tag) {
state[/* value */1] = Caml_option.some(signal[0]);
return /* () */0;
} else {
state[/* sourceTalkback */2] = signal[0];
return /* () */0;
}
}));
Curry._1(notifier, (function (signal) {
var match = state[/* value */1];
if (typeof signal === "number") {
state[/* ended */0] = true;
state[/* sourceTalkback */2](/* Close */1);
return sink(/* End */0);
} else if (signal.tag) {
if (match !== undefined && !state[/* ended */0]) {
state[/* value */1] = undefined;
return sink(/* Push */Block.__(1, [Caml_option.valFromOption(match)]));
} else {
return /* () */0;
}
} else {
state[/* notifierTalkback */3] = signal[0];
return /* () */0;
}
}));
return sink(/* Start */Block.__(0, [(function (signal) {
if (signal) {
state[/* ended */0] = true;
state[/* sourceTalkback */2](/* Close */1);
return state[/* notifierTalkback */3](/* Close */1);
} else {
state[/* sourceTalkback */2](/* Pull */0);
return state[/* notifierTalkback */3](/* Pull */0);
}
})]));
});
});
}
exports.sample = sample;
/* No side effect */