Promise sequence sample

node v8.17.0
version: 3.0.0
endpointsharetweet
let MySampleFunction = () => { return new Promise((resolve, reject) => { setTimeout(() => { let theText = 'initial function' console.log(theText) resolve(theText) }, 1000) }) } MySampleFunction() .then((input) => { return new Promise((resolve, reject) => { let theText = 'second function' setTimeout(() => { console.log(Math.round(new Date() / 1000) + ': ' + input + ', ' + theText) resolve(theText) }, 1000) }) }) .then((input) => { return new Promise((resolve, reject) => { let theText = 'third function' setTimeout(() => { console.log(Math.round(new Date() / 1000) + ': ' + input + ', ' + theText) resolve(theText) // reject(new Error('Sucks to be you ;)')) }, 1000) }) }) .then((input) => { return new Promise((resolve, reject) => { let theText = 'fourth function' setTimeout(() => { console.log(Math.round(new Date() / 1000) + ': ' + input + ', ' + theText) resolve(theText) }, 1000) }) }) .catch((e) => { console.log('Shit hit the fan', e) })
Loading…

no comments

    sign in to comment