Stream promise resolve
A transform stream that resolves using promises limiting concurrency.
This is useful, for say, a website crawler where you have a stream of pages to visit and want to limit the number of simultaneous requests.
npm install stream-promise-resolve
Example
const request = ;const Resolve = ;const stream = // Some means of getting an object stream of urls // Download our urls 10 at a timestream ;
Usage
Extend the resolve class and provide a _resolve
function. This will be passed the chunk
and encoding
arguments from stream._transform
. It should return a Promise
. The return from this promise will be passed to the readable side of the stream.
Setting maxParallel
option will control how many promises can run concurrently.
{ // Method should return a promise }
new Resolve({ resolve, maxParallel, maintainOrder })
Creates a transform stream. objectMode
will default to true. This can be overridden by setting objectMode
, readableObjectMode
, or writableObjectMode
.
Arguments:
resolve
<Function>
Implementation of theResolve._resolve
method.maxParallel
<Number>
Maximum number of promises to run concurrently. Defaults to1
.maintainOrder
<Boolean>
Should resolved promises be returned in the same order as they entered the stream. Defaults totrue
.