-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync.js
More file actions
47 lines (41 loc) · 1.25 KB
/
Copy pathasync.js
File metadata and controls
47 lines (41 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Youtube: https://www.youtube.com/watch?v=V_Kr9OSfDeU
// Used to make promises easier to work with
function makeRequest(location){
return new Promise((resolve, reject) => {
console.log(`Making request to ${location}`)
if(location === 'Google'){
resolve('Google says hi')
} else {
reject('We can only talk to Google')
}
})
}
function processRequest(response) {
return new Promise((resolve, reject) => {
console.log('Processing response')
resolve('Extra Information + ' + response)
})
}
// makeRequest("Google").then(response => {
// console.log('Response Received')
// return processRequest(response)
// }).then(info => {
// console.log(info)
// }).catch(err => {
// console.log(err)
// })
// async const jawns = (location) => {
async function jawn(location) {
try {
// Need the 'await' or it will return the promise,
// not the result of the promise being executed
let response = await makeRequest(location)
console.log('Response Received')
let output = await processRequest(response)
console.log(output)
} catch (err) {
console.log(err)
}
// Catch will return the first error
}
jawn('Goole')