refactor: simple
This commit is contained in:
parent
1af713cfb8
commit
6d6a22d527
|
@ -70,39 +70,15 @@ export class Actions extends decorate(Traversals) {
|
||||||
}
|
}
|
||||||
|
|
||||||
parallel(context) {
|
parallel(context) {
|
||||||
const promises = [];
|
let immediate = true;
|
||||||
const results = [];
|
const results = this.traversals.map((traversal) => {
|
||||||
const tickingPromises = [];
|
|
||||||
for (let i = 0; i < this.traversals.length; i++) {
|
|
||||||
const traversal = this.traversals[i];
|
|
||||||
const result = traversal.traverse(context);
|
const result = traversal.traverse(context);
|
||||||
|
if (result instanceof Promise) {
|
||||||
|
immediate = false;
|
||||||
|
}
|
||||||
results.push(result);
|
results.push(result);
|
||||||
if (result instanceof TickingPromise) {
|
});
|
||||||
tickingPromises.push(result);
|
return immediate ? results : TickingPromise.all(results);
|
||||||
result.then(() => {
|
|
||||||
tickingPromises.splice(tickingPromises.indexOf(result), 1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (result instanceof Promise) {
|
|
||||||
promises.push(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tickingPromises.length > 0) {
|
|
||||||
return new TickingPromise(
|
|
||||||
(resolve) => {
|
|
||||||
resolve(Promise.all(results));
|
|
||||||
},
|
|
||||||
(elapsed) => {
|
|
||||||
for (let i = 0; i < tickingPromises.length; i++) {
|
|
||||||
tickingPromises[i].tick(elapsed);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (promises.length > 0) {
|
|
||||||
return Promise.all(results);
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prologue() {
|
prologue() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user