Skip to content

Instantly share code, notes, and snippets.

@ashwinkumar2438
Created February 19, 2022 21:43
Show Gist options
  • Save ashwinkumar2438/6b62ee6f1d3a943bdd977c1eccfd2bec to your computer and use it in GitHub Desktop.
Save ashwinkumar2438/6b62ee6f1d3a943bdd977c1eccfd2bec to your computer and use it in GitHub Desktop.
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