Skip to content

Commit

Permalink
feat(csv-issues-esm): more transform config in sample
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Oct 11, 2023
1 parent df337ec commit 0c2acf1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions demo/issues-esm/labo/361-transform.js
Expand Up @@ -12,8 +12,12 @@ const config = {
highWaterMark: 1,
// Number of records to generate, `-1` for infinite
length: -1,
// Number of parallel handler execution, `100` by default
parallel: 100,
// Generate object or strings, both are supported
objectMode: false,
// Use a write delay comprised between 0 and the `config.write_delay` value
random_delay: true,
// Write delay, `0` to write instantly
write_delay: 1000,
};
Expand Down Expand Up @@ -64,7 +68,7 @@ const consume = new Writable({
setTimeout(() => {
count++;
callback();
}, config.write_delay);
}, config.random_delay ? Math.random() * config.write_delay : config.write_delay);
}
},
});
Expand All @@ -80,8 +84,14 @@ await pipeline(
highWaterMark: config.highWaterMark,
}),
// Step 2 - transform
transform({ parallel: 100, highWaterMark: 1 }, function (chunk, next) {
next(null, JSON.stringify(chunk) + "\n");
transform({ parallel: config.parallel, highWaterMark: 1 }, function (chunk) {
// Sync
// return JSON.stringify(chunk) + "\n"
// Async
return new Promise( (resolve) => {
resolve(JSON.stringify(chunk) + "\n");
})

}),
// Step 3 - consume
consume
Expand Down

0 comments on commit 0c2acf1

Please sign in to comment.