Skip to content

Commit 442b8d4

Browse files
committed
Async and Await
1 parent f89638f commit 442b8d4

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

12_Asynchronous_Concepts/script2.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@ const fetchPhotoDetails = (photo) => {
2626
});
2727
};
2828

29-
fetchUser("Shubham")
30-
.then((user) => fetchUserPhotos(user.username))
31-
.then((photos) => fetchPhotoDetails(photos[0]))
32-
.then((details) => console.log(`Your photo details are ${details}`));
29+
// This was one way of calling the function
30+
// fetchUser("Shubham")
31+
// .then((user) => fetchUserPhotos(user.username))
32+
// .then((photos) => fetchPhotoDetails(photos[0]))
33+
// .then((details) => console.log(`Your photo details are ${details}`));
34+
35+
// The second way is using Async ==> Await
36+
37+
const displayData = async () => {
38+
const user = await fetchUser("Shubham");
39+
const photos = await fetchUserPhotos(user.username);
40+
const details = await fetchPhotoDetails(photos[0]);
41+
42+
console.log(details);
43+
};
44+
45+
displayData();

0 commit comments

Comments
 (0)