Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript promise state

// 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;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #promise #state
ADD COMMENT
Topic
Name
2+3 =