Skip to content

Instantly share code, notes, and snippets.

@thomasmichaelwallace
Created July 11, 2017 17:53
Show Gist options
  • Save thomasmichaelwallace/d7a31d083ab9598c8ce1db7914db8640 to your computer and use it in GitHub Desktop.
Save thomasmichaelwallace/d7a31d083ab9598c8ce1db7914db8640 to your computer and use it in GitHub Desktop.
A promise wrapper for mocking asynchronous functions with a bit of chaos.
const chaosPromise = result => (
Math.random() >= 0.5
? Promise.resolve(result)
: new Promise(res => setTimeout(() => res(result), Math.random() * 1000))
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment