const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('foo');
}, 300);
});
myPromise
.then(handleResolvedA, handleRejectedA)
.then(handleResolvedB, handleRejectedB)
.then(handleResolvedC, handleRejectedC);
new Promise((resolve, reject) => {
if (ok) { resolve(result) }
else { reject(error) }
})
async function abc()
{
Promise.resolve("hello world").then(function(value)
{
console.log(value);
}
JS
copy
let done = true
const isItDoneYet = new Promise((resolve, reject) => {
if (done) {
const workDone = 'Here is the thing I built'
resolve(workDone)
} else {
const why = 'Still working on something else'
reject(why)
}
})
async function abc()
{
const myPromise = new Promise(function(resolve, reject) {
resolve("hello world");
});
let y= await myPromise;
console.log(y);
/*"hello world*/
}
let promise = new Promise(function(resolve, reject){
//do something
});
getData()
.then(data => console.log(data))
.catch(error => console.log(error));