Skip to content

Instantly share code, notes, and snippets.

@ashwinkumar2438
Created February 21, 2022 04:08
Show Gist options
  • Save ashwinkumar2438/1608314ca85ec8ef4d93c1477827098a to your computer and use it in GitHub Desktop.
Save ashwinkumar2438/1608314ca85ec8ef4d93c1477827098a to your computer and use it in GitHub Desktop.
class PromiseCopy{
static reject( reason ){
// We return a new Promise and pass the reason to reject method if Promise.reject is called directly.
if( !( this instanceof PromiseCopy ) ) return new PromiseCopy( ( _ , rej ) => rej( reason ) ) ;
//return if promise is settled.
if( this.#state !== states.pending )return ;
this.#state = states.rejected ;
this.#result = reason ;
this.#dispatchCallbacks();
}
#dispatchCallbacks(){ /* */ } ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment