forked from iarv/sthlm-mesh
22 lines
550 B
JavaScript
22 lines
550 B
JavaScript
let nodes = [];
|
|
let fetchPromise = null;
|
|
|
|
async function fetchNodes() {
|
|
if (nodes.length > 0) return;
|
|
|
|
if (!fetchPromise) {
|
|
fetchPromise = fetch('https://map.sthlm-mesh.se/api/v1/nodes/')
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
nodes = data.nodes;
|
|
fetchPromise = null; // reset after successful fetch
|
|
})
|
|
.catch(err => {
|
|
fetchPromise = null; // reset on failure
|
|
throw err;
|
|
});
|
|
}
|
|
|
|
await fetchPromise;
|
|
}
|