Last active
December 7, 2018 15:43
-
-
Save jvwong/341150637b899535c91faba1322cffdf to your computer and use it in GitHub Desktop.
Promises and timers
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
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