redioactive
Version:
Reactive streams for chaining overlapping promises.
86 lines (85 loc) • 3.18 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const redio_1 = __importStar(require("../redio"));
async function run() {
await (0, redio_1.default)([1, 2, 3, 4, 5, 6], { debug: false })
.flatMap((x) => (0, redio_1.default)([x]), { debug: false })
.each(console.log, { debug: false })
.done(() => {
console.log('There we go!');
})
.toPromise();
await (0, redio_1.default)([1, 2, 3, 4, 5, 6], { debug: false })
.flatMap((x) => {
// let sent = false
return (0, redio_1.default)(() => {
return [x, redio_1.end];
}, { oneToMany: true });
}, { debug: false })
.each(console.log, { debug: false })
.done(() => {
console.log('There we go!');
})
.toPromise()
.then(console.log);
await (0, redio_1.default)([1, 2, 3, 4, 5, 6], { debug: false })
.flatMap((x) => {
let sent = false;
return (0, redio_1.default)(() => {
const y = sent ? redio_1.end : x;
sent = true;
return y;
}, { oneToMany: false });
}, { debug: false })
.each(console.log, { debug: false })
.done(() => {
console.log('There we go!');
})
.toPromise();
await (0, redio_1.default)([1, 2, 3, 4, 5, 6], { debug: false })
.flatMap((x) => {
return (0, redio_1.default)(() => {
return [x, redio_1.end];
}, { oneToMany: true });
}, { debug: false })
.each(console.log, { debug: false })
.done(() => {
console.log('There we go!');
})
.toPromise();
await (0, redio_1.default)([1, 2, 3, 4, 5, 6], { debug: false })
.flatMap((x) => (0, redio_1.default)((push, next) => {
push(x);
push(redio_1.end);
next();
}, { oneToMany: false }), { debug: false })
.each(console.log, { debug: false })
.done(() => {
console.log('There we go!');
})
.toPromise();
}
run().catch(console.error);