-
Notifications
You must be signed in to change notification settings - Fork 1
/
Fallback.ts
25 lines (20 loc) · 897 Bytes
/
Fallback.ts
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
import type Feature from 'ol/Feature.js';
import type LineString from 'ol/geom/LineString.js';
import type {Profiler} from './index';
type FallbackOptions = {
profilers: Profiler[];
};
export default class Fallback implements Profiler {
private profilers: Profiler[];
constructor(options: FallbackOptions) {
this.profilers = options.profilers;
}
computeProfile(segment: Feature<LineString>): Promise<void> {
// array of computeProfile functions.
const functions = this.profilers.map(profiler => () => profiler.computeProfile(segment));
// execute the promises in sequence, the first resolved will be returned. All the following
// will execute "identity" function instead of the real function.
// @ts-ignore don't know why TSC is unhappy with this nice code
return functions.reduce((cur, nextFn) => cur.then(val => val, nextFn), Promise.reject());
}
}