Last active
February 21, 2022 03:52
-
-
Save ashwinkumar2438/f0cda4a8858a48f9218ef7675965735a to your computer and use it in GitHub Desktop.
Revisions
-
ashwinkumar2438 revised this gist
Feb 21, 2022 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,12 +7,14 @@ class PromiseCopy{ */ if( !( this instanceof PromiseCopy ) ) return new PromiseCopy( res => res( value ) ) ; //return if promise is settled. if( this.#state !== states.pending )return ; //If value is a thenable object we call Promise.resolve recursively by passing it to value.then. if( isThenable( value ) ) return value.then( PromiseCopy.resolve.bind( this ), PromiseCopy.resolve.bind( this ) ); this.#state = states.fulfilled ; this.#result = value ; this.#dispatchCallbacks(); -
ashwinkumar2438 revised this gist
Feb 21, 2022 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,6 @@ class PromiseCopy{ //If value is a thenable object we call Promise.resolve recursively by passing it to value.then. if( isThenable( value ) ) return value.then( PromiseCopy.resolve.bind( this ), PromiseCopy.resolve.bind( this ) ); -
ashwinkumar2438 created this gist
Feb 21, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ class PromiseCopy{ static resolve( value ){ /* 1. We return a new Promise and pass the value to resolve method if Promise.resolve is called directly. 2. The resolve method of executor runs this same code with this instance added. */ if( !( this instanceof PromiseCopy ) ) return new PromiseCopy( res => res( value ) ) ; //If value is a thenable object we call Promise.resolve recursively by passing it to value.then. if( isThenable( value ) ) return value.then( PromiseCopy.resolve.bind( this ), PromiseCopy.resolve.bind( this ) ); this.#state = State.fulfilled ; this.#result = value ; this.#dispatchCallbacks(); } #dispatchCallbacks(){ /* */ } ; }