Concurrency promise controller, is a tool class implemented by typescript which can limit the number of concurrency promises executed simultaneously.
The x-concurrency-promise is designed to execute promises simultaneously, while developers can add tasks or pause execution anytime.
const pool = new XConcurrencyPromise(5);
new Array(100).fill(0).forEach(() => {
pool.feed(
() =>
new Promise((resolve) => setTimeout(resolve, Math.random() * 5000, true))
);
});
setTimeout(() => {
pool.freeze();
}, 1000);
setTimeout(() => {
pool.unfreeze();
});
Trigger when the pool start.
Trigger when turning to item promise.
Trigger when the item promise aborting.
Trigger when the pool stop.
You can set the concurrency limit at any time, but it will never stop your task which is start.
Put a task into the concurrency pool.
You can assign a key to group your task and use other methods to handle them, like the freeze
method.
Put an array of tasks into the concurrency pool.
Freeze your tasks with the group key you assign.
When you freeze your task executing now, it will never stop the task, but there will trigger an event called 'onAbort'.
Freeze all tasks.
Opposite to freeze.
Opposite to freeze all.