Skip to content

Commit

Permalink
fix: support AsyncIterator for stream API
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmlnc committed Jun 9, 2019
1 parent 9b04800 commit b32842d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ function stream(source: Pattern | Pattern[], options?: Options): NodeJS.Readable

const works = getWorks(source, ProviderStream, options);

/**
* The stream returned by the provider cannot work with an asynchronous iterator.
* To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams.
* This affects performance (+25%). I don't see best solution right now.
*/
return utils.stream.merge(works);
}

Expand Down
8 changes: 0 additions & 8 deletions src/utils/stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import * as util from './stream';

describe('Utils → Stream', () => {
describe('.merge', () => {
it('should return source stream as is, when he is alone', () => {
const source = new stream.PassThrough();

const actual = util.merge([source]);

assert.strictEqual(actual, source);
});

it('should merge two streams into one stream', () => {
const first = new stream.PassThrough();
const second = new stream.PassThrough();
Expand Down
8 changes: 0 additions & 8 deletions src/utils/stream.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import merge2 = require('merge2');

export function merge(streams: NodeJS.ReadableStream[]): NodeJS.ReadableStream {
/**
* Multiplexing leads to the creation of a new stream.
* If the source is one, then there is nothing to multiplex.
*/
if (streams.length === 1) {
return streams[0];
}

const mergedStream = merge2(streams);

streams.forEach((stream) => {
Expand Down

0 comments on commit b32842d

Please sign in to comment.