mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-07 00:05:49 +00:00
17 lines
399 B
TypeScript
17 lines
399 B
TypeScript
import { delay } from 'es-toolkit'
|
|
|
|
export async function withMinimumDuration<T>(
|
|
task: Promise<T> | (() => Promise<T>),
|
|
minimumMs = 1000,
|
|
): Promise<T> {
|
|
const startedAt = Date.now()
|
|
try {
|
|
return await (typeof task === 'function' ? task() : task)
|
|
} finally {
|
|
const remaining = minimumMs - (Date.now() - startedAt)
|
|
if (remaining > 0) {
|
|
await delay(remaining)
|
|
}
|
|
}
|
|
}
|