feat: TickingPromise.all

This commit is contained in:
cha0s 2019-09-08 07:39:31 -05:00
parent d9004f0e5a
commit 708c4fe25d

View File

@ -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);
}