diff --git a/16_Ajax_Restful_Api/HTML/index.html b/16_Ajax_Restful_Api/HTML/index.html index cbfe135..5dea138 100644 --- a/16_Ajax_Restful_Api/HTML/index.html +++ b/16_Ajax_Restful_Api/HTML/index.html @@ -32,7 +32,8 @@

JavaScript

- + + \ No newline at end of file diff --git a/16_Ajax_Restful_Api/Js/76_16_10_Asinc_and_Await.js b/16_Ajax_Restful_Api/Js/76_16_10_Asinc_and_Await.js index e69de29..b7298f6 100644 --- a/16_Ajax_Restful_Api/Js/76_16_10_Asinc_and_Await.js +++ b/16_Ajax_Restful_Api/Js/76_16_10_Asinc_and_Await.js @@ -0,0 +1,48 @@ + + +async function AsyncFunction(){ + return "Not need Promise" +} + + +// AsyncFunction().then(res => console.log(res)) + +let isError = true; + +function GetCategory(){ + return new Promise((resolve, reject)=>{ + setTimeout(()=>{ + if (!isError){ + resolve("Phone") + }else{ + reject("Some Error ") + } + },1000) + }) +} + + +function GetProduct(category){ + return new Promise((resolve, reject)=>{ + setTimeout(()=>{ + resolve(`5 prodacts in ${category}`) + },1000) + }) +} + + +GetCategory().then(GetProduct).then(res =>console.log(res)).catch(err => console.log(err)) + +async function GetProducts(){ + + try{ + let category = await GetCategory(); + let result = await GetProduct(category); + console.log(result) + }catch(error){ + console.log(error) + } + +} + +GetProducts() \ No newline at end of file