const anotherPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('this is the eventual value the promise will return');
}, 300);
});
// CONTINUATION
anotherPromise
.then(value => { console.log(value) })
const count = true;
let countValue = new Promise(function (resolve, reject) {
if (count) {
resolve("There is a count value.");
} else {
reject("There is no count value");
}
});
console.log(countValue);
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
});
getSomethingWithPromise()
.then(data => {/* do something with data */})
.catch(err => {/* handle the error */})
let hw = await new Promise((resolve)=>{
resolve(“HELLO WORLD”);
})
console.log(hw);
/*basically in resolve(whatever') the whatever is returned*/
/*hw will console.log out "HELLO WORLD" */
// jeffBuysCake is a promise
const promise = jeffBuysCake('black forest')
/* Testing Grepper
function examplePromise(){
let promiseToReturn = new Promise(function (resolve, reject) {
let sum;
setTimeout(function(){
sum = 5 + 6;
if(sum > 10) {
resolve(sum);
}else{
reject('The promise has been rejected');
}
}, 2000);
});
return promiseToReturn;
}
console.log('some piece of code');
examplePromise().then(function(result){
console.log(result);
}).catch(function(error){
console.log(error);
});
console.log('another piece of code');