mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
17 lines
398 B
TypeScript
17 lines
398 B
TypeScript
export const monotonicResolve = <T>(
|
|
promises: (Promise<T> | false)[],
|
|
callback: (value: T) => void,
|
|
) => {
|
|
let latestResolvedIndex = -1;
|
|
promises
|
|
.filter((promise) => !!promise)
|
|
.forEach((promise, index) => {
|
|
promise.then((value) => {
|
|
if (index > latestResolvedIndex) {
|
|
latestResolvedIndex = index;
|
|
callback(value);
|
|
}
|
|
});
|
|
});
|
|
};
|