Skip to content

Instantly share code, notes, and snippets.

@Drag13
Created January 31, 2024 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drag13/42ef694b241d103ae22d46f88ccb4a36 to your computer and use it in GitHub Desktop.
Save Drag13/42ef694b241d103ae22d46f88ccb4a36 to your computer and use it in GitHub Desktop.
Timeout base delay for testing purposes
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