Created
December 31, 2024 11:21
-
-
Save jpb06/3288be6b1863bca14297792aa97b8050 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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