Skip to content

Commit

Permalink
Merge pull request #42 from chingu-voyages/fix-response
Browse files Browse the repository at this point in the history
Response count decreased
  • Loading branch information
andreimaier authored Oct 28, 2023
2 parents 40cc519 + 7afa3a8 commit 9652c7a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Food-Recipe/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//User Input
let responseCount = 0;
document.addEventListener("DOMContentLoaded", () => {
const form = document.querySelector("form");
const searchInput = document.querySelector(".search__input");
const nameElement = document.querySelector(".ingredient-searched");


if (form && searchInput) {
form.addEventListener("submit", (event) => {
Expand All @@ -12,6 +14,7 @@ document.addEventListener("DOMContentLoaded", () => {
nameElement.innerHTML = " ";
nameElement.appendChild(searched);
clearResults();
responseCount=0;
Autocomplete(searchInput.value);
});
} else {
Expand All @@ -27,9 +30,13 @@ const fetchQueue = []; // Queue to manage fetch requests

async function executeFetchQueue() {
while (fetchQueue.length > 0) {
if(responseCount>=2){
break;
}
const { recipeName, originalName } = fetchQueue.shift();
await fetchThumbnailVideoDescription(recipeName, originalName);
await new Promise((resolve) => setTimeout(resolve, 1000 / RATE_LIMIT));
responseCount++;
}
}
// Fetching AutoComplete the User input
Expand Down

0 comments on commit 9652c7a

Please sign in to comment.