Skip to content

Instantly share code, notes, and snippets.

@jvwong
Last active December 7, 2018 15:43
Show Gist options
  • Save jvwong/341150637b899535c91faba1322cffdf to your computer and use it in GitHub Desktop.
Save jvwong/341150637b899535c91faba1322cffdf to your computer and use it in GitHub Desktop.
Promises and timers
const TIMEOUT = 5000;
const promiseTimeout = delay => new Promise( ( resolve, reject ) => setTimeout( () => reject( new Error('fake timeout') ), delay ) );
const doSomethingAsync = ( ) => {
return Promise.resolve()
.then( () => promiseTimeout( TIMEOUT ) );
};
// logs 'TimeoutError'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment