diff --git a/src/index.ts b/src/index.ts index 29f4dacd..b274291d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); } diff --git a/src/utils/stream.spec.ts b/src/utils/stream.spec.ts index 7e726436..d7a947ef 100644 --- a/src/utils/stream.spec.ts +++ b/src/utils/stream.spec.ts @@ -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(); diff --git a/src/utils/stream.ts b/src/utils/stream.ts index cf9e665c..bcb8ff75 100644 --- a/src/utils/stream.ts +++ b/src/utils/stream.ts @@ -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) => {