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
0 answers

How to resolve a Promise to its value in an object returned by a synchronous function?

tl;dr I'm trying to return a data object in a synchronous function (which cannot be declared async due to the API constraints), but some of my data is in the form of Promise objects. I can delay the callback until after the promises are resolved…
0
votes
0 answers

Django Celery show return value of task

I have a problem to display the return value of my celery task to the client. Redis is my result backend. Thats the code: tasks.py: @shared_task def create_task(task_type): sleep(int(task_type) * 5) data={ 'test':'test' } …
Hacknym
  • 1
  • 1
0
votes
0 answers

Is normal code inside a promise body executed synchronously?

Can anyone please explain why the result of the below code is - 1,2,3,4,5,6? Does this imply that normal code within the promise body executes synchronously? I was under the impression that the result of the promise depends on how it is handled by…
Ankit_M
  • 276
  • 1
  • 3
  • 15
0
votes
1 answer

What should be the Content-type header in this fetch API Javascript Code?

fetch(url, { method: 'post', headers: { "Content-type": }, body: 'bar= foo& lorem=ipsum' }) Should it be? A) application/x-www-form-urlencoded; charset=UTF-8 B) text/html; charset=utf-8 C) application/json;…
Jojo
  • 71
  • 1
  • 2
  • 5
0
votes
0 answers

Using exponential backoff on chained requests

I have chained requests on GA API, meaning the second requests uses result from the first request. I wanted to use exponentialBackoff() function to retry if there is an error (status 429 for example). My question is, what would be the best way of…
0
votes
1 answer

Mapping over array of object with promises

I need to map over array of objects and change "photo property" in every object into it's base64 representation from the url im storing in databse. For this purpose I'm using imageToBase64 library for node.js. But the problem is I cannot generate…
0
votes
1 answer

Do I get right how asynchrony works behind the scene in JS?

I have a question about asynchrony in JS. How it actually works. I'm not sure if I got it right, I hope you can help me figure it out. So, I have a code: console.log('start'); setTimeout(() => console.log('one'),…
Jhon
  • 37
  • 5
0
votes
1 answer

Array Reduce method freezes CSS Animation until it is done

The following snippet of code freezes the CSS animation until it is done. I can't figure out why. I tried promises, async await, setTimeout, nothing changed. I want to have nice and simple loading animation to show in the browser while the following…
0
votes
1 answer

How to get asynchronous data into a global array in React.js?

I want to insert asynchronous data from Firestore into React elements. I have a couple of functions that handle the flow. getEvents() is an asynchronous function that returns an array of objects that is my data from Firestore. const getEvents =…
0
votes
1 answer

How to run setState function in ReactJs synchronously?

I want all these setState functions to run synchronously because as you can see, the functions running next to it depends on some of the value and it would produce the wrong result if the value is not updated. I have tried many solutions like…
0
votes
1 answer

Array logs in the console as a pupulated array of objects but individual elements as undefined

I hope to be clear in my first question here. I was trying to perform a sort on the exhibitors array and while troubleshooting I got these confusing logs in the console. When I am console logging an array it shows the list of objects but logging an…
0
votes
1 answer

Javascript input event taking time for next character , input listener asynchronous

I am facing a problem in my code and I am not getting a solution please help me, Here Is The Script var obj=[ {name:'sourav',age:20}, {name: 'gautam', age:…
0
votes
0 answers

Manifest v3 extension: asynchronous event listener does not keep the service worker alive

With manifest v3, we will need to store state data to the local storage with chrome.storage.local and load it when needed. But that API is asynchronous, so when it is called inside an event listener, sometimes the service worker is unloaded without…
0
votes
1 answer

Node.js Promise.all method not working as expected for saving multiple mongoose documents

I know of the Model.create(documentsArray) and also Model.bulkSave(documentsArray) mongoose API's. I was just experimenting with the Promise.all the following way - const promises = [] for(let i=1; i++; i<1000) { const promise = new…
0
votes
1 answer

Best practice using promises chaining in node JS

I'm little bit confusing in promises. first, I have some ugly code like this: async function presence(ctx) { try { var prsenceData = []; var isSuccess = Boolean(false); var ckFilePath = "./somepath/cookie.json"; …
Rafik Bojes
  • 71
  • 1
  • 9