augmenttoolkit / client /src /services /weatherQueue.ts
Leon4gr45's picture
Upload folder using huggingface_hub (part 2)
cd99321 verified
Raw
History Blame Contribute Delete
562 Bytes
import { weatherApi } from '../api/client'
const MAX_CONCURRENT = 3
let active = 0
const queue: Array<() => void> = []
function acquire(): Promise<void> {
if (active < MAX_CONCURRENT) { active++; return Promise.resolve() }
return new Promise(resolve => queue.push(resolve))
}
function release(): void {
const next = queue.shift()
if (next) next()
else active--
}
export async function fetchWeather(lat: number, lng: number, date: string) {
await acquire()
try {
return await weatherApi.get(lat, lng, date)
} finally {
release()
}
}