Questions tagged [asynchronous-javascript]

Asynchronous JavaScript is a technique to load JavaScript asynchronously using async and defer attributes or script tag injection. Not to be confused with AJAX.

164 questions
0
votes
1 answer

Why doesn't this run asynchronously (for with Promise inside)?

I am a novice in javascript and I've been learning about promises, recently I started working in some simple list that is retrieved with a random delay (setTimeout), a classical I think. After trying and doing some research I found I post that…
0
votes
0 answers

Should the caller of an asynchronous function be asynchronous?

Should the caller function (CR) be declared with async keyword and hence be an asynchronous function when the callee function (CE) is declared with async keyword and is an asynchronous function? Assume that there is no other asynchronous task…
Srishti Gupta
  • 1,155
  • 1
  • 13
  • 30
0
votes
2 answers

multiple promises in Marko

In Marko, how can one multiple promises in parallel? For example, I am looking for something like this: <@then|result1, result2|> promise1 and promise2 are resolved in parallel ${result1} renders…
0
votes
1 answer

How are variables in a call stack in JavaScript still accessible after the function returns

Two points of confusion: How are function frames preserved and disposed? Example: function foo() { var a = ...; setTimeout(function() { console.log(a); },50); return a; } In this example, the inner function in setTimeout is…
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
0
votes
2 answers

Why these codes about the timer(setTimeout()), the then() method of Promises running like this?

const wait = function () { return new Promise(function (resolve, reject) { resolve() setTimeout(console.log('a'), 5000) }) } wait().then(() => console.log('b')) Explain the code: As you can see above, i created a wait() function that…
0
votes
1 answer

What do the gaps mean in the diagram given in page 181, chapter 11: Asynchronous programming in the book Eloquent Javascript?

I was reading "Eloquent Javascript", chapter 11 on asynchronous programming and there is a diagram given on page 181 contrasting the differences in single threaded, multithreaded and asynchronous techniques in the case of sending two network…
0
votes
0 answers

Why is my JavaScript asynchronous function not running till everything else finishes?

I am having a bit of a hard time understanding how javascript asynchronous functions work. In my actual use case, the function in question is a 3rd part API call but a simple setTimeout function is a simpler way to reproduce my problem. I expect the…
0
votes
2 answers

Error Handling in Javascript asynchronous functions. Conceptual query. Possibility of Having an umbrella try-catch in node.js for multiple layers

Queries: Why does the try block not catch the error in the asynchronous method in Javascript? Could it be understood in terms of execution context? Is there a way in which we could wrap all error handling in the entry file or at a higher…
0
votes
1 answer

Javascript asynchronous web crawler

I have an async function that reads a list of websites from a csv file. async function readCSV(){ const fileStream = fs.createReadStream('./topm.csv'); const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity …
0
votes
2 answers

Async and Await not working with Axios React

I am trying to test my react project locally with my computer and with my phone. I am using JavaScript not TypeScript. When I run the project on my computer everything works fine, but when I try to load it on my phone, I get an error: Unhandled…
0
votes
1 answer

Javascript create async function without breaking the application

I have a project where I have a horizontal bar that has an overflow. At the beginning and end there are buttons that move the overflow position. At this point the user has to click on the buttons in order to move the overflow. I wan't to create…
Stephen
  • 913
  • 3
  • 24
  • 50
0
votes
0 answers

React app keeps sending multiple request on its own

I'm new to react and I'm trying to build a Weather App for my project. It keeps sending the request to the API I'm using which is OpenWeatherMap API. I'm using Axios to send the request. Here's what my code looks like: import React, {useEffect,…
0
votes
1 answer

Use DirectionServices asynchronously

I am a Java developer student and I have a problem understanding how to properly write asynchronous functions in Javascript. I read a lot of tutorials but I don't find a good way to implement proper asynchronous methods all the time. I am making an…
0
votes
0 answers

How to render an asynchronous result (array) in a component in react?

I have been doing js for about a month now, and I am writing this program where I am using clarifai API to see which celebrity a person on the photo resembles the most. I want to pass the output as props to Rank component to render it, but I get…
0
votes
1 answer

How can I read lines from .txt file, save in array, and print array asynchronously?

I have a .txt file that I want to save in a JS array and then console.log that array. I know from this answer how to read the file into an array, but the problem is when I try to console.log the array, it logs it as empty. Here's my code: const fs =…