Skip to content

Commit 3ed3ac1

Browse files
11 - Promises and Async
1 parent 2c59010 commit 3ed3ac1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function success(x) {
2+
console.log('success', x.data)
3+
}
4+
5+
function error(err) {
6+
console.log('err', err.data)
7+
}
8+
9+
// function handleResolve(resolve){
10+
11+
// }
12+
13+
// ajax -> XMLHttpRequest, fetch
14+
const laundryPromise = new Promise(resolve=>{
15+
resolve({data: "Take out laundry"})
16+
17+
//throw ({data: "This is an error. I forgot"})
18+
19+
}) // built-in class
20+
21+
// console.log(laundryPromise)
22+
23+
// laundryPromise.then(success).catch(error)
24+
25+
// console.log("When does this run??")
26+
27+
async function helloThere () {
28+
const result = await laundryPromise.catch(x=>{
29+
throw(x)
30+
})
31+
// return result
32+
}
33+
34+
helloThere().then(x=>{
35+
console.log(x)
36+
}).catch(x=>{
37+
console.log('err', x)
38+
})
39+
// console.log(result)

0 commit comments

Comments
 (0)