hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBc35a83aBurak Boduroğlu4 months ago440 commits
| 1 | import { client } from "../client"; |
| 2 | import type { Limits } from "../client"; |
| 3 | |
| 4 | let cachedLimits: Limits | null = null; |
| 5 | let pendingLimits: Promise<Limits> | null = null; |
| 6 | |
| 7 | export function getLimits(signal?: AbortSignal): Promise<Limits> { |
| 8 | if (cachedLimits) return Promise.resolve(cachedLimits); |
| 9 | if (pendingLimits) return pendingLimits; |
| 10 | pendingLimits = client<Limits>("/limits", { signal }) |
| 11 | .then((limits) => (cachedLimits = limits)) |
| 12 | .finally(() => { |
| 13 | pendingLimits = null; |
| 14 | }); |
| 15 | return pendingLimits; |
| 16 | } |
| 17 | |
| 18 | export function setCachedLimits(limits: Limits | null): void { |
| 19 | cachedLimits = limits; |
| 20 | pendingLimits = null; |
| 21 | } |