Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

583 B
Raw Blame
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, lang?: string) {
  await acquire()
  try {
    return await weatherApi.get(lat, lng, date, lang)
  } finally {
    release()
  }
}