177 questions
-1
votes
2
answers
90
views
Waiting for all side promises to finish before "then()" execution
In section then3 I want to generate promises with further operations on their content inside 2 "thens". In case they were fetches, I want to limit their start to for example 3 at once every ...
1
vote
1
answer
25
views
Angular: data not rendering correctly
people.
I have a Angular application which I am integrating with a node.js server. It works like this:
A service is injected in the component
The component calls the getAccountData() function from ...
0
votes
0
answers
28
views
How to wait for dynamically loaded external js file and then execute it's instance as a global variable [duplicate]
I'm trying to dynamically call external JS files. I'm using promise to wait for file to be loaded and then execute the code. How ever I don't want to run all the code inside positive promise. I'd like ...
4
votes
2
answers
93
views
Sequence of rejected promise with Promise.reject()
I am learning microtask queue and i have a simple question.
With the following code:
Promise.resolve().then(()=>console.log("Resolved1 Promise"));
Promise.reject().then(()=>console.log("...
0
votes
1
answer
75
views
Promises execution order in Microtask Queue
const p1 = new Promise((_, reject) => {
reject(1);
}).then((r)=>console.log(r)).catch((r)=>console.log(r));
const p2 = new Promise((resolve, _) => {
resolve(10);
}).then((r)=>...
0
votes
2
answers
84
views
Understanding Promise Chaining Internal Mechanics
I am learning promise chaining and I stumbled upon a doubt. Consider the below promise chain -
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("...
-1
votes
1
answer
114
views
Can clearTimeout prevent the execution of a callback which has already been moved to the callback queue?
Consider a scenario where I have two tasks -
Task 1 is a callback which is set to be executed after 1 sec using setTimeout.
Task 2 is a synchronous/blocking task which takes comparatively more time ...
2
votes
1
answer
49
views
Empty result using FileReader and promise
I am struggling a bit with asynchronous operations and Promises (a quite new concept to me) using FileReader. I have found a very interesting thread about it there, but can't make my script to work ...
0
votes
0
answers
30
views
Is an object returned by a call to an async (external) process fundamentally different from an object that is returned from a 'normal' function?
I am quite new to Javascript, with my main programming experience in assembly language programming of micro-controllers. It has taken quite some time to adjust to it having so many 'system calls', (to ...
-2
votes
2
answers
401
views
Is there a meaningful difference between an async IIFE and a new Promise? [duplicate]
Consider the following assignments:
const promise1 = (async () => {
await someAsyncFunction();
})();
const promise2 = new Promise(async resolve => {
await someAsyncFunction();
...
2
votes
1
answer
78
views
Nested asynchronous javascript (microtask and macrotasks queues)
Recently I've been given a following problem:
console.log("start");
const promise1 = Promise.resolve().then(() => {
console.log("promise1");
const timer2 = setTimeout(() => {
...
1
vote
1
answer
65
views
Explain the output of the following code by describing the micro task queue and call stack architecture
This is the code:
function SSD() {
console.log('SSD')
}
async function createData() {
let status = undefined
try {
const res = await fetch('https://api.github.com/users/Soumya-...
1
vote
0
answers
891
views
firefox failing a post request - NS_BINDING_ABORTED
My case - "form data to be auto saved before navigating to new page". Firefox is cancelling form post with "NS_BINDING_ABORTED" and navigating to new page. Body - onbeforeunload is ...
2
votes
1
answer
87
views
Passing a primitive to a then handler
This is an interesting observation that I have made when experimenting with promises in JS. Consider this code:
Promise.resolve(1).then(2).then(console.log);
This prints out 1 as its output. ...
2
votes
1
answer
188
views
Does JS event loop always prioritize microtask queue over macrotask queue? [duplicate]
I was recently watching a workshop video by Will Sentence on async javascript and I am having trouble understanding whether microtask queue always has priority over macrotask queue.
function display(...
0
votes
0
answers
35
views
I need to write an asynchronous function in JavaScript that sleeps for (millis) milliseconds and can resolve any value, but am unsure about await [duplicate]
I received this as a coding challenge, but am unfamiliar with the concepts of promises, awaits, and awaits.
// Asynchronous function that sleeps for a number of milliseconds
async function sleep(...
0
votes
1
answer
81
views
How to execute a script after an external asynchronous script in header tag completes execution?
With Webflow native custom code editor, I added to my website an external script made by Finsweet inside the <head> tag, as they instruct to do.
I want to make some changes in the page with my ...
0
votes
1
answer
61
views
async http request breaks fake-timers
I need to combine simulated discrete time events that I faked with fake-timers with real http requests. Here is an example code
const FakeTimers = require("@sinonjs/fake-timers");
const ...
2
votes
3
answers
95
views
Is there any purpose to wrapping an async function in a promise?
I'm just inherited a new codebase and this pattern in javascript seems to do nothing:
/**
* Update Data Model
* @param {Object} model
* @param {String} field
* @param {Mixed} value
*/
function ...
-1
votes
1
answer
197
views
Asynchronous JavaScript without a built-in asynchronous method [duplicate]
All examples I see about Asynchronous JavaScript when they use callbacks, promises or async/await with a delay, to fake examples like waiting for something, make use of setTimeout() or setInterval(). ...
4
votes
2
answers
236
views
Does the JS engine create a new microtask that will execute every handler chained together in a Promise object when resolve is invoked?
I recently encountered this question on Stack Overflow, asking about how the then method really works in JavaScript. The responder, Trincot, made the following comment:
The host will check which job ...
3
votes
3
answers
1k
views
Is the promise returned by the 'then' function the same as the promise returned by the callback inside this 'then' function?
So, I was recently introduced to the concept of promises and I was told for chaining purpose, we use 'then', which is actually invoked when the attached promise object is fulfilled. And, to do some ...
1
vote
1
answer
261
views
Can element in JOB QUEUE be completed after element in TASK QUEUE?
community! I've been recently discovering how JavaScript works and came across interesting moment with order of elements being executed in Job Queue and Task Queue.
As we all know, Job Queue has ...
0
votes
0
answers
55
views
Looping while receiving data from async request module
I am a newbie in Node.JS. I am trying to fetch data from an api and filtering out data from a miscellaneous response. But my while loop is getting into infinite loop as the res array never gets ...
0
votes
0
answers
122
views
How to efficiently manage multiple asynchronous tasks with error handling in Node.js?
I'm working on a Node.js project that involves performing multiple asynchronous tasks (API calls, database queries, etc.) concurrently. I want to ensure that my code is efficient and maintainable, ...
0
votes
1
answer
98
views
order of execution of several fetch calls
What I'm trying to do is: from my single page application, get data from an API using fetch. If the JWT is expired, ask the API for a new JWT and then renew the request for data.
I tried to implement ...
4
votes
4
answers
2k
views
How can I wait for asynchronous operations to complete when an Electron app is closed?
I have an Electron JS desktop application that is supposed to do some closing operations when it's closed or quit. However, the app is closing before my asynchronous operations are ended.
How can I ...
0
votes
0
answers
83
views
How to make event listener run asynchronously in events module of Node without using setImmediate() or process.nextTick()?
In my API I want to execute long running function call in background and I dont want to use any task queue like RabbitMQ.
I am trying to run long running function using events module of Node. But ...
1
vote
1
answer
61
views
Returning result from asynchronous function using callbacks
I have to write the body of a function getABC() which essentially has to take in responses from 3 different functions, getA()(synchronous),getB(callback)(callback driven),getC() (promise based). ...
0
votes
1
answer
63
views
Asynchronous Javascript Promises code stop at "order created", how to fix the issue? [duplicate]
I wanted to convert callback hell to promises.
function createOrder() {
setTimeout(function() {
console.log("order created");
setTimeout(function() {
console.log("...
0
votes
1
answer
49
views
Inconsistent output using do/while and for loop in asynchronous JavaScript using let to declare the variables [duplicate]
Why do I get a different output when using a do/while loop in the code below?
function logNum() {
let counter = 0;
do {
counter += 1;
setTimeout(() => console.log(counter), counter * ...
0
votes
2
answers
642
views
Vuex action does not work properly in a vue mounted hook
I'm building a small e-commerce store with an admin panel for myself.
I use Firebase firestore as my backend to store all the user's data.
I have a root 'users' collection with a document for every ...
0
votes
1
answer
241
views
Jonas Schmedtmann's Asynchronous coding - Chaining Promises - restcountries issue
I'm having trouble to return a few keys from objects which are coming from promises callback function. The error I'm getting is on second country:
Uncaught (in promise) TypeError: Cannot read ...
0
votes
0
answers
576
views
How to resolve a Promise to its value in an object returned by a synchronous function? [duplicate]
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 ...
2
votes
1
answer
2k
views
Asynchronous javascript: How to run a function during the execution of another function
Im trying to wrap my head around asynchronous javascript. So I wrote a function to test some things out. What I'm trying to do is write a scenario where I'm:
Putting Popcorn in the microwave
During ...
-1
votes
1
answer
86
views
What's the order of execution when we have callback inside promise?
I am new to JavaScript and, am not able to understand why the output of the following code:-
let promise = new Promise((res, rej) => {
setTimeout(() => {
console.log("promise executed&...
-1
votes
1
answer
55
views
I'm new to javascript promise so I can't understand this [duplicate]
This is the sample code:
// Use zipURL to receive long and lat by using zipcode
const userInfo = document.getElementById('userInfo');
const generate = document.getElementById('generate');
// Function ...
0
votes
2
answers
2k
views
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; ...
-1
votes
2
answers
1k
views
Javascript await reading text file
This is probably dead simple, but I can't quite figure it out. I simply want to read the contexts of a text file into a variable. What I have is:
async function load(path) {
try {
const ...
2
votes
1
answer
100
views
How do I destructure an array wrapped in the Promise keyword in javascript? [duplicate]
I am trying to retrieve data from a PSQL table. And this is my code for that:
async function requestData() {
var selectQuery = `SELECT "fName", "lName", "phoneNumber", ...
1
vote
0
answers
46
views
JavaScript Event Loop Queues Terminology
I've been reading a lot of tutorials as well as posts in StackOverflow regarding Event Loop in Javascript (Browser/NodeJS) and i'm currently a bit consfused on the terminology used when referring to ...
-1
votes
4
answers
1k
views
Prevent code from blocking the event loop
I'm figuring out how to prevent any blocking code from blocking the main event loop.
Suppose there's a function (let's assume it's going to block the event loop if implemented synchronously):
function ...
1
vote
0
answers
647
views
How to use async-await function when using connect-mongo with AWS Secrets Manager
Currently, I'm using AWS Secrets Manager to store my MongoDB (Atlas) ID and password.
It is working fine for connecting to the DB; however, I'm facing challenges when I am trying to use the same ID ...
0
votes
0
answers
298
views
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).
...
1
vote
0
answers
42
views
Trouble understanding the flow of this Promise chain
async function chicks(nest, year) {
let list = "";
await Promise.all(network(nest).map(async name => {
list += `${name}: ${
await anyStorage(nest, name, `chicks in ${year}`)
...
0
votes
1
answer
625
views
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 ...
0
votes
1
answer
65
views
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(() => ...
0
votes
1
answer
150
views
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 ...
0
votes
1
answer
189
views
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 ...
0
votes
1
answer
150
views
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 ...