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 c6f78b5
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions stuff/js/es6/promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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))
.then(() => {
console.log(678)

throw new Error('901')
})

// console.log(345)
// VM1316:29 345
// undefined
// 563-10c5b65a2ff77937.js:1 123
// window.console.error @ 563-10c5b65a2ff77937.js:1
// overrideMethod @ console.js:288
// (anonymous) @ VM1316:15
// Promise.catch
// (anonymous) @ VM1316:14
// Show 1 more frame
// Show less
// 563-10c5b65a2ff77937.js:1 Error: 012
// at <anonymous>:18:15
// window.console.error @ 563-10c5b65a2ff77937.js:1
// overrideMethod @ console.js:288
// (anonymous) @ VM1316:22
// Promise.catch
// (anonymous) @ VM1316:22
// Show 1 more frame
// Show less
// VM1316:24 678
// VM1316:26 Uncaught (in promise) Error: 901
// at <anonymous>:26:15

0 comments on commit c6f78b5

Please sign in to comment.