Fixed scenario_loader

This commit is contained in:
Daniel Vestøl committed 2019-04-20 18:00:01 +02:00
1 parent b7ce4a18a4
commit 82141ac9d7
3 files changed
+4 -173

No files matched your search

+4 -9
View File
@@ -103,19 +103,14 @@ class AsyncArray extends Array {
super(arr)
this.data = arr; // In place of Array subclassing
}
}
filterAsync(predicate) {
async filterAsync(predicate) {
// Take a copy of the array, it might mutate by the time we've finished
const data = Array.from(this.data);
// Transform all the elements into an array of promises using the predicate
// as the promise
return Promise.all(data.map((element, index) => predicate(element, index, data)))
// Use the result of the promises to call the underlying sync filter function
.then(result => {
return data.filter((element, index) => {
return result[index];
});
const result = await Promise.all(data.map((element, index) => predicate(element, index, data)));
return data.filter((element, index) => {
return result[index];
});
}
}