Mini Promise Sample

node v8.16.1
version: 3.0.0
endpointsharetweet
const times2 = (i) => { return new Promise((resolve, reject) => { // setTimeout(() => { // reject(new Error('Timeout, duurde te lang')) // }, 900) setTimeout(() => { let o = (i || 1) * 2 console.log(o) resolve(o) }, 1000) }) } times2(10) .then(times2).then((i) => { return new Promise((resolve, reject) => { let o = i * 10 resolve(o) // Nothing happens from here since the promise resolved // console.log(o) let myError = new Error('Error thingy') myError.dummyValue = 'Pepper & Dino' reject(myError) }) }) .then(times2) .catch((c) => { console.log('Stuff broke', c.dummyValue) })
Loading…

no comments

    sign in to comment