Last active
February 19, 2022 20:51
-
-
Save ashwinkumar2438/5375d27db0fffef5bdd6ec9470ca8019 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 error = null ; | |
//const error = 'error' ; // change to a truthy value to reject promise. | |
const promise = new Promise( ( resolve, reject ) => { | |
//asynchronous operation | |
setTimeout( () => { | |
return error ? reject( error ) : resolve( 'final data' ) ; | |
}, 3000 ); | |
} ); | |
// before 3 seconds: | |
Promise {<pending>} | |
[[PromiseState]]: "pending" | |
[[PromiseResult]]: undefined | |
//resolved after 3 seconds : | |
Promise {<fulfilled>: 'final data'} | |
[[PromiseState]]: "fulfilled" | |
[[PromiseResult]]: "final data" | |
//rejected after 3 seconds : | |
Promise {<rejected>: 'error'} | |
[[PromiseState]]: "rejected" | |
[[PromiseResult]]: "error" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment