// Check the state of a Promise
function yet(promise) {
const yettable = {
state: "pending",
isPending() { return promise.state == "pending"; },
isFulfilled() { return promise.state == "fulfilled"; },
isRejected() { return promise.state == "rejected"; },
};
Object.assign(promise, yettable);
promise
.then(result => (promise.state = "fulfilled", result))
.catch(err => (promise.state = "rejected", err));
return promise;
}