Skip to content

Commit

Permalink
Update async.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sahilverma0146 committed Jul 25, 2024
1 parent bad8104 commit 38de923
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions async.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// },2000 );
// }
// // callback-hell
// getData(1, ()=>{
// getData(1, ()=>{ // 1--- dataid
// getData(2 , ()=>{
// getData(3,()=>{
// getData(4);
Expand All @@ -56,12 +56,12 @@
// let promise = new Promise ((resolve, reject) =>{ // RESOLVE --- OUR TASK IS COMPLETED REJECT --- OUR TASK IS FILLFULL WITH SOME ERRORS
// console.log("i am a promise");
// resolve("fillfulled");
// reject("some error")
// // reject("some error");
// });


// promise --- promise.catch() --- use for rject
// --- promise.then() --- use for resolve
//promise --- promise.catch() --- use for rject
// --- promise.then() --- use for resolve
// const getPromise =()=>{
// return new Promise ((resolve, reject) =>{
// console.log("i am a promise");
Expand Down Expand Up @@ -205,19 +205,20 @@ function api(){

// by async wait we hold the execution that we hold by the promise-chainning

// async function getWetherData(){
// await api(); // 1st call
// console.log("api(2) is calling now");
// await api();// 2nd
async function getWetherData(){
console.log("api(1) is calling now");
await api(); // 1st call
console.log("api(2) is calling now");
await api();// 2nd

// }
}

// better way
// async await >> promise-chain >> callback-Hell

// IIFE --- IMMEDIATELY INVOKED FUNCTION EXPRESSION --- USE FOR DIRECT EXECUTION NOT REQ OF FUNCTION CALLBACK
( async function getWetherData(){
await api(); // 1st call
console.log("api(2) is calling now");
await api();// 2nd
})();
// ( async function getWetherData(){
// await api(); // 1st call
// console.log("api(2) is calling now");
// await api();// 2nd
// })();

0 comments on commit 38de923

Please sign in to comment.