Skip to content

Commit

Permalink
add promises demos #51
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbarzi committed Aug 1, 2024
1 parent ee09c64 commit d818c2c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions stuff/js/es6/promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
new Promise((resolve, reject) => {
// setTimeout(() => resolve(123), 1000)
setTimeout(() => reject(123), 1000)
})
//.then(value => console.log(value), error => console.error(error))
.then(value => console.log(value))
//.catch(error => console.error(error))
.then(() => {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(456), 1000)
})
})
.then(value => console.log(value))
.catch(error => {
console.error(error)

//return 789
throw new Error('012')
})
//.then(value => console.log(value), error => console.error(error))
.then(value => console.log(value))
.catch(error => console.error(error))

// console.log(345)
// VM1281: 24 345
// undefined
// 563 - 10c5b65a2ff77937.js: 1 123
// window.console.error @563-10c5b65a2ff77937.js: 1
// overrideMethod @console.js: 288
// (anonymous) @VM1281: 15
// Promise.catch
// (anonymous) @VM1281: 14
// Show 1 more frame
// Show less
// 563 - 10c5b65a2ff77937.js: 1 Error: 012
// at < anonymous >: 18: 15

0 comments on commit d818c2c

Please sign in to comment.