Skip to content

Instantly share code, notes, and snippets.

@adufilie
Last active March 23, 2017 20:39
Show Gist options
  • Save adufilie/327ddd763a766a3ad87fea1b45cf9c48 to your computer and use it in GitHub Desktop.
Save adufilie/327ddd763a766a3ad87fea1b45cf9c48 to your computer and use it in GitHub Desktop.
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