Files
desktop/app/providers/DialogProvider/dialogQueue.ts

19 lines
754 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
let tail: Promise<void> = Promise.resolve();
/**
* Ставит функцию в очередь на выполнение.
* Все функции выполняются последовательно, одна за другой.
* Если функция выбрасывает ошибку, она логируется,
* а выполнение очереди продолжается
* @param fn функция
*/
export const runTaskInQueue = (fn: () => Promise<void>) => {
tail = tail.then(fn).catch((e) => {
console.error("Dialog queue error", e);
});
};
/**
* Ждет, пока все пакеты попадающие в очередь не будут обработаны
*/
export const whenFinish = () => tail;