Default to an objectMode: true instance but allow creating other instances with other defaults

This commit is contained in:
Lewis Diamond
2020-08-03 18:54:40 -04:00
parent 4aac05c9c0
commit 87c44de799
32 changed files with 241 additions and 76 deletions

15
samples/parallelMap.js Normal file
View File

@@ -0,0 +1,15 @@
const strom = require("stromjs").strom();
function sleep(time) {
return time > 0 ? new Promise(resolve => setTimeout(resolve, time)) : null;
}
strom
.fromArray([1, 2, 3, 4, 6, 8])
.pipe(
strom.parallelMap(async d => {
await sleep(10000 - d * 1000);
return `${d}`;
}, 3),
)
.pipe(process.stdout);

21
samples/rate.js Normal file
View File

@@ -0,0 +1,21 @@
const strom = require("../dist/index.js");
function sleep(time) {
return time > 0 ? new Promise(resolve => setTimeout(resolve, time)) : null;
}
const rate = strom.rate(2, 1, { behavior: 1 });
rate.pipe(strom.map(x => console.log(x)));
async function produce() {
rate.write(1);
await sleep(500);
rate.write(2);
await sleep(500);
rate.write(3);
rate.write(4);
rate.write(5);
await sleep(500);
rate.write(6);
}
produce();