Last active
March 23, 2017 20:39
-
-
Save adufilie/327ddd763a766a3ad87fea1b45cf9c48 to your computer and use it in GitHub Desktop.
This file contains 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
export default function rejectLaterMaybe<R>(result:R, rejectProbability:number = 0.1, delay:number = 500):Promise<R> | |
{ | |
return new Promise((resolve, reject) => setTimeout(() => { | |
if (Math.random() < rejectProbability) | |
reject(new Error(`Oops! ${JSON.stringify(result).substr(0, 256)}`)); | |
else | |
resolve(result); | |
}, 500)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment