Last active
February 26, 2022 12:02
-
-
Save ashwinkumar2438/1681801ccc70222c91bb60e147e892f8 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
class PromiseCopy{ | |
finally( callback ){ | |
// resolveOrReject : forward current #state. | |
// value : forward current #result. | |
/** curried function to pass Promise.resolve or | |
Promise.reject forward based on current Promise #state. **/ | |
const commonCallback = ( resolveOrReject ) => ( value ) => { | |
const response = callback?.() ; | |
return Promise.resolve( response ).then( _ => resolveOrReject( value ) ); | |
} | |
return this.then( commonCallback( Promise.resolve ) , commonCallback( Promise.reject ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment