mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-03 05:55:03 +01:00
chore(utils): optimized promiseAllSequence
This commit is contained in:
@@ -12,14 +12,13 @@ export const promiseAllSequence = async <
|
||||
actions: Fn[],
|
||||
) => {
|
||||
const results: R[] = [];
|
||||
await actions.reduce(
|
||||
(promise, fn) =>
|
||||
// 2. then call action, store result and repeat
|
||||
promise.then(fn).then(result => {
|
||||
results.push(result);
|
||||
return result;
|
||||
}),
|
||||
Promise.resolve(), // 1. Resolve initial promise
|
||||
);
|
||||
// For some reason, the previous implementation with promise chaining
|
||||
// (https://github.com/trezor/trezor-suite/blob/100015c45451ed50e2b0906d78de73c0fd2883d1/packages/utils/src/promiseAllSequence.ts)
|
||||
// was significantly slower in some cases, therefore simple for cycle is used instead
|
||||
for (let i = 0; i < actions.length; ++i) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const result = await actions[i]();
|
||||
results.push(result);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user