Skip to content

Instantly share code, notes, and snippets.

@jpb06
Created December 31, 2024 11:21
Show Gist options
  • Select an option

  • Save jpb06/3288be6b1863bca14297792aa97b8050 to your computer and use it in GitHub Desktop.

Select an option

Save jpb06/3288be6b1863bca14297792aa97b8050 to your computer and use it in GitHub Desktop.
const delay = async (ms: number) =>
new Promise((resolve) => {
setTimeout(resolve, ms);
});
const enforceMinimumDuration = async <TResult>(
promise: Promise<TResult>,
minDuration: number,
) => {
const [result] = await Promise.all([promise, delay(minDuration)]);
return result;
};
const p = Promise.resolve('Yolo bro');
const result = await enforceMinimumDuration(p, 1_000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment