mirror of
https://github.com/codex-team/editor.js
synced 2024-05-19 06:47:16 +02:00
b39996616c
* renderer batching * initialization and rendering performance optimized * insertMany api method added * Update index.html * rm old method * upd changelog * upd paragraph * paste tests fixed * api blocks tests fixed * backspace event tests fixed * async issues in tests fixed * eslint * stub block added, tests added * eslint * eslint * add test for insertMany() * Update package.json
29 lines
769 B
TypeScript
29 lines
769 B
TypeScript
/**
|
|
* Class allows to make a queue of async jobs and wait until they all will be finished one by one
|
|
*
|
|
* @example const queue = new PromiseQueue();
|
|
* queue.add(async () => { ... });
|
|
* queue.add(async () => { ... });
|
|
* await queue.completed;
|
|
*/
|
|
export default class PromiseQueue {
|
|
/**
|
|
* Queue of promises to be executed
|
|
*/
|
|
public completed = Promise.resolve();
|
|
|
|
/**
|
|
* Add new promise to queue
|
|
*
|
|
* @param operation - promise should be added to queue
|
|
*/
|
|
public add(operation: (value: void) => void | PromiseLike<void>): Promise<void> {
|
|
return new Promise((resolve, reject) => {
|
|
this.completed = this.completed
|
|
.then(operation)
|
|
.then(resolve)
|
|
.catch(reject);
|
|
});
|
|
}
|
|
}
|