I want to use Subject has an async task queue with concurrency = 1.
Gathering new tasks is faster than performaning those tasks so, as a performance optimization, I would like to process all un-processed tasks until now.
The following code goes over task by task:
this.tasks
.pipe(
mergeMap(async task => {
await this.processTasks([task])
}, 1),
)
I would like to covert the above code to something similar to:
this.tasks
.pipe(
mergeMap___AllUnprocessedUntilNow(async tasks => {
await this.processTasks(tasks)
}, 1),
)
- I can't use
bufferTimeorbufferCountbecause they will introduce additiol latency to every new task.
Actual Run Result:
* adding task 1
* procssing task 1 (takes alot of time to perform it)
* meanwhile, adding more tasks: 2,3,4
* processed task 1
* procssing task 2
* processed task 2
* procssing task 3
* processed task 3
* procssing task 4
* processed task 4
Expected Run Result:
* adding task 1
* procssing task 1 (takes alot of time to perform it)
* meanwhile, adding more tasks: 2,3,4
* processed task 1
* procssing task 2,3,4
* processed task 2,3,4