Files
APIPark/frontend/packages/common/src/utils/ux.ts
T
ScarChin 73435497a2 Feature/1.4 (#154)
- Load balancing (can connect to multiple accounts, automatically switch accounts when there is no quota)
- AI call log
- Model rate configuration
2025-01-07 18:47:08 +08:00

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
})
}