mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-07-06 16:11:56 +08:00
73435497a2
- Load balancing (can connect to multiple accounts, automatically switch accounts when there is no quota) - AI call log - Model rate configuration
12 lines
370 B
TypeScript
12 lines
370 B
TypeScript
export const withMinimumDelay = <T>(fn: () => Promise<T>, delay: number = 100): Promise<T> => {
|
|
const startTime = Date.now()
|
|
return fn().then(async (result) => {
|
|
const endTime = Date.now()
|
|
const elapsed = endTime - startTime
|
|
if (elapsed < delay) {
|
|
await new Promise((resolve) => setTimeout(resolve, delay - elapsed))
|
|
}
|
|
return result
|
|
})
|
|
}
|