Skip to content

Instantly share code, notes, and snippets.

@jeron-diovis
Created February 21, 2023 10:25
Show Gist options
  • Select an option

  • Save jeron-diovis/4b8ca8ac50b7091f82cc2c6b6ae4bb72 to your computer and use it in GitHub Desktop.

Select an option

Save jeron-diovis/4b8ca8ac50b7091f82cc2c6b6ae4bb72 to your computer and use it in GitHub Desktop.
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