Created
February 19, 2022 21:43
-
-
Save ashwinkumar2438/6b62ee6f1d3a943bdd977c1eccfd2bec 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 states = { | |
pending: 'PENDING', | |
fulfilled: 'FULFILLED', | |
rejected: 'REJECTED' | |
} | |
class PromiseCopy{ | |
#state = states.pending // initial state of promise | |
#result = undefined ; | |
constructor( executor ){ | |
try{ | |
executor( PromiseCopy.resolve.bind( this ), PromiseCopy.reject.bind( this ) ) | |
} | |
catch( e ){ | |
PromiseCopy.reject.call( this, e ) ; // reject promise when error thrown. | |
} | |
} | |
static resolve(){ /**/ } | |
static reject(){ /**/ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment