forked from iTowns/itowns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSourceProvider.js
More file actions
27 lines (24 loc) · 1.17 KB
/
Copy pathDataSourceProvider.js
File metadata and controls
27 lines (24 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export default {
executeCommand(command) {
const layer = command.layer;
const src = command.extentsSource;
const dst = command.extentsDestination || src;
const promises = src.map((from, i) => (layer.getData(from, dst[i])));
// partialLoading sets the return promise as fulfilled if at least one sub-promise is fulfilled
// It waits until all promises are resolved
if (command.partialLoading) {
return Promise.allSettled(promises)
.then((results) => {
const anyFulfilledPromise = results.find(promise => promise.status === 'fulfilled');
if (!anyFulfilledPromise) {
// All promises failed -> reject
const err = new AggregateError(results.map(r => r.reason), 'Failed to load any data');
return Promise.reject(err);
}
return results.map(prom => (prom.value ? prom.value : null));
});
}
// Without partialLoading, the return promise is rejected as soon as any sub-promise is rejected
return Promise.all(promises);
},
};