Attaches callback functions for the resolution and/or rejection of the promise.
then(onfulfilled?, onrejected?)
onfulfilled optional
The callback function to execute when the promise is resolved.
onrejected optional
The callback function to execute when the promise is rejected.
A promise for the completion of which ever callback is executed.
let p = new Promise((resolve, reject) => {
resolve("hello")
})
p.then(value => print(value))
hello
let p = new Promise((resolve, reject) => {
reject(new Error("something happened"))
})
p.then(value => print('resolved:', value), error => print('rejected:', error.message))
rejected: something happened