Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including status-for-promise with all npm packages installed. Try it out:

const { addStatusToPromise } = require("status-for-promise"); // Create a promise that will resolve in 2 seconds const promiseForACake = new Promise((resolve, reject) => { setTimeout(() => resolve("chocolate cake"), 2000); }); // A recursive function that will rerun every second until the // promise resolves. // This will simulate an async action or a user-triggered action const bugTheChef = (promiseForFood) => { const { isSettled, isFulfilled, value } = promiseForFood; console.log("Chef is my food ready?"); if (isSettled && isFulfilled) { console.log(`Yes, check your table for your ${value}.` + "\n"); } else { console.log("No, its not ready yet. Go away.\n"); setTimeout(() => bugTheChef(promiseForFood), 1000); } }; // Lets add the status properties addStatusToPromise(promiseForACake); // What to do when the promise resolves promiseForACake.then((food) => console.log(`Your ${food} is served.` + "\n")); // lets bug the chef about our the food bugTheChef(promiseForACake);

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

status-for-promise v0.2.4

Adds status, value, isPending, isFulfilled and isRejected properties to a promise or a promise-like object

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free