feat: TickingPromise.all
This commit is contained in:
parent
d9004f0e5a
commit
708c4fe25d
|
@ -78,6 +78,29 @@ export class TickingPromise extends Promise {
|
|||
this.ticker = ticker;
|
||||
}
|
||||
|
||||
static all(promises) {
|
||||
const tickingPromises = [];
|
||||
for (let i = 0; i < promises.length; i++) {
|
||||
const promise = promises[i];
|
||||
if (promise instanceof TickingPromise) {
|
||||
tickingPromises.push(promise);
|
||||
}
|
||||
}
|
||||
if (0 === tickingPromises.length) {
|
||||
return super.all(promises);
|
||||
}
|
||||
return new TickingPromise(
|
||||
(resolve) => {
|
||||
resolve(Promise.all(results));
|
||||
},
|
||||
(elapsed) => {
|
||||
for (let i = 0; i < tickingPromises.length; i++) {
|
||||
tickingPromises[i].tick(elapsed);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
tick(elapsed) {
|
||||
this.ticker(elapsed, this.resolve, this.reject);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user