Files
gods-eye-view/src/sources/requestDeadline.js
T
f4fcf267c6 fix(osm): stop using public Overpass by default (#648) (#742)
Traffic roads come from OpenFreeMap vector tiles, or TomTom flow tiles with a
key (Hybrid by default). Military areas use OpenFreeMap polygons with a bundled
worldwide name index; wide views show named points. ALPR reads an hourly
OpenStreetMap extract. Cockpit place context and country, state and US county
outlines use bundled Natural Earth and US Census data. Overpass is used only
when an operator configures their own endpoint.

Also: camera arrivals no longer land below ground, keyless terrain retries on
429, bounded relation geometry for configured Overpass, one shared
OpenStreetMap credit, and separate tile and API transports for embedders.

Co-authored-by: theGaryLarson <[email protected]>
Co-authored-by: Milan Khanal <[email protected]>
2026-09-28 19:07:57 -05:00

44 lines
1.5 KiB
JavaScript

/** Bound acquisition and body consumption, including transports that ignore abort. */
export async function requestWithDeadline(operation, { signal, timeoutMs }) {
const controller = new AbortController();
const cancel = () => controller.abort(signal.reason);
if (signal?.aborted) cancel();
else signal?.addEventListener('abort', cancel, { once: true });
let rejectWait;
const aborted = new Promise((_, reject) => {
rejectWait = reject;
});
const rejectAbort = () => rejectWait(controller.signal.reason);
controller.signal.addEventListener('abort', rejectAbort, { once: true });
const timer = setTimeout(
() =>
controller.abort(new DOMException('Request timed out', 'TimeoutError')),
timeoutMs,
);
try {
controller.signal.throwIfAborted();
return await Promise.race([operation(controller.signal), aborted]);
} finally {
clearTimeout(timer);
signal?.removeEventListener('abort', cancel);
controller.signal.removeEventListener('abort', rejectAbort);
controller.abort();
}
}
/** Cancel one consumer's wait without cancelling a shared acquisition. */
export async function waitForSignal(promise, signal) {
if (!signal) return promise;
signal.throwIfAborted();
let cancel;
const aborted = new Promise((_, reject) => {
cancel = () => reject(signal.reason);
signal.addEventListener('abort', cancel, { once: true });
});
try {
return await Promise.race([promise, aborted]);
} finally {
signal.removeEventListener('abort', cancel);
}
}