Default to an objectMode: true instance but allow creating other instances with other defaults
This commit is contained in:
15
samples/parallelMap.js
Normal file
15
samples/parallelMap.js
Normal 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
21
samples/rate.js
Normal 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();
|
||||
Reference in New Issue
Block a user