Published
Edited
Apr 24, 2018
4 stars
Insert cell
Insert cell
Insert cell
async function f(){
return 1;
}
Insert cell
Insert cell
f().then((res)=>{return `I got ${res}. When I did .then() on it`})
Insert cell
Insert cell
async function fActual(){
return Promise.resolve(1);
}
Insert cell
fActual().then((res) =>{return `The actual result is ${res} too`})
Insert cell
Insert cell
Insert cell
async function fwithAwait(){
var a = await new Promise((resolve, reject)=>{
setTimeout(() => resolve(1), 1000)
});
return a;
}
Insert cell
fwithAwait()
Insert cell
Insert cell
fwithAwait().then((res)=> `I got ${res}. So yes we can`)
Insert cell
Insert cell
fwithAwait().then((res)=> `First ${res}`)
.then((res)=> `Second ${res}`)
.then((res)=> `Third ${res}`)
.then((res)=> `Fourth ${res}`)
Insert cell
Insert cell
{
function normal(){
var a = new Promise((resolve, reject) => {
setTimeout(() => resolve(1), 1000)
})

return await a;
}
return normal();

}
Insert cell
Insert cell
Insert cell
Insert cell
{
async function goat(){
let goatImage = await fetch('http://goat-error');
return goatImage;
}
return goat().then(()=>`Success!`)
.catch((err) => `Ther was an error: ${err} `);
}
Insert cell
Insert cell
{
async function goatFail(){
let goatImage = await fetch('http://goat-error');
return goatImage;
}
return goatFail().then(()=>`Mutton Biryani`)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more