RxJS equivalent of Async.js mapLimit

Async.js mapLimit , and its family of functions <name>Limitbasically works as a semaphore: they allow you to run a limited number of tasks at the same time and additional incoming tasks are added to the queue. The queue becomes the producer (cold? Connected?). The script starts the object from the queue as soon as the place becomes available (one of its tasks ends).

Thus, a limited number of concurrent tasks are always active.

How can I achieve similar functionality in RxJS?

+4
source share
1 answer

defer flatMapWithMaxConcurrent - RxJs:

// returns a promise
function runSomeJob(input) { ... }

function runSomeJobObservable(input) {
    return Rx.Observable.defer(function () {
        return runSomeJob(input);
    });
}

var inputStream = // some Rx.Observable

// only allow 5 jobs to run concurrently
var outputStream = inputStream
    .flatMapWithMaxConcurrent(5, runSomeJobObservable);

ouputStream.subscribe(...);
+4

All Articles