Created
February 21, 2023 10:25
-
-
Save jeron-diovis/4b8ca8ac50b7091f82cc2c6b6ae4bb72 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
| function use(promise) { | |
| if (promise.status === 'fulfilled') { | |
| return promise.value; | |
| } else if (promise.status === 'rejected') { | |
| throw promise.reason; | |
| } else if (promise.status === 'pending') { | |
| throw promise; | |
| } else { | |
| promise.status = 'pending'; | |
| promise.then( | |
| result => { | |
| promise.status = 'fulfilled'; | |
| promise.value = result; | |
| }, | |
| reason => { | |
| promise.status = 'rejected'; | |
| promise.reason = reason; | |
| }, | |
| ); | |
| throw promise; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment