Files
yaak-mountain-loop/src-web/lib/minPromiseMillis.ts
Gregory Schier 5919fae739 Run oxfmt across repo, add format script and ignore config
Format all non-generated files with oxfmt via `vp fmt`. Add
.oxfmtignore to skip bindings/ and wasm-pack output. Add npm
format script and update DEVELOPMENT.md docs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 09:52:11 -07:00

20 lines
486 B
TypeScript

import { sleep } from "./sleep";
/** Ensures a promise takes at least a certain number of milliseconds to resolve */
export async function minPromiseMillis<T>(promise: Promise<T>, millis = 300) {
const start = Date.now();
let result: T;
try {
result = await promise;
} catch (e) {
const delayFor = millis - (Date.now() - start);
await sleep(delayFor);
throw e;
}
const delayFor = millis - (Date.now() - start);
await sleep(delayFor);
return result;
}