@vbarbarosh/node-helpers 3.47.1 → 3.47.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.47.1",
5
+ "version": "3.47.2",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -1,8 +1,9 @@
1
1
  const stream = require('stream');
2
2
 
3
- function stream_discard()
3
+ function stream_discard({objectMode = false} = {})
4
4
  {
5
5
  return new stream.Writable({
6
+ objectMode,
6
7
  write: function (buffer, encoding, callback) {
7
8
  callback();
8
9
  },
@@ -53,7 +53,7 @@ function stream_map_parallel({handler, concurrency})
53
53
  callback_next = null;
54
54
  tmp();
55
55
  }
56
- if (callback_flush && !buf.length) {
56
+ if (callback_flush && !running) {
57
57
  callback_flush();
58
58
  }
59
59
  }
@@ -0,0 +1,26 @@
1
+ const Promise = require('bluebird');
2
+ const assert = require('assert');
3
+ const stream = require('stream');
4
+ const stream_each = require('./stream_each');
5
+ const stream_map_parallel = require('./stream_map_parallel');
6
+
7
+ describe('stream_map_parallel', function () {
8
+ it('basic', async function () {
9
+ const r = Array(100).fill().map((v,i) => i);
10
+ const out = [];
11
+ await stream.promises.pipeline(
12
+ stream.Readable.from(r),
13
+ stream_map_parallel({
14
+ concurrency: 5,
15
+ handler: async function (num) {
16
+ await Promise.delay(0);
17
+ return num;
18
+ },
19
+ }),
20
+ stream_each(function (item) {
21
+ out.push(item);
22
+ }),
23
+ );
24
+ assert.deepStrictEqual(out, r);
25
+ });
26
+ });