Created
January 31, 2024 11:17
-
-
Save Drag13/42ef694b241d103ae22d46f88ccb4a36 to your computer and use it in GitHub Desktop.
Timeout base delay for testing purposes
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
type DelayOptions = | |
| { timeout: number; shouldFail?: boolean } | |
| { timeout?: number; shouldFail: boolean }; | |
function delayed<T>( | |
data: T, | |
options: DelayOptions = { shouldFail: false, timeout: 1500 } | |
) { | |
const { shouldFail, timeout } = options | |
return new Promise<T>((resolve, reject) => { | |
setTimeout(() => (shouldFail ? reject(data) : resolve(data)), timeout); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment