-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsync_Await.js
49 lines (42 loc) · 1.12 KB
/
Async_Await.js
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
48
49
// jshint esversion: 8
function makeRequest(location) {
return new Promise((resolve, reject) => {
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(processedResponse => {
console.log(processedResponse);
});
// makeRequest("Facebook").then((message) => {
// console.log("Response Received!");
// return processRequest(message);
// }).then((message) => {
// console.log(message);
// }).catch((message) => {
// console.log(message);
// });
async function doWork() {
try {
const response = await makeRequest("Google");
// console.log(response);
console.log("Response Received");
const processedResponse = await processRequest(response);
console.log(processedResponse);
} catch (err) {
console.log(err);
}
}
doWork();