Questions tagged [promise]

Promises are a tactic for deferred computing, suitable for several styles of concurrency: thread and event loop concurrency for local computation, and both synchronous and asynchronous remote messaging. A promise represents the eventual result of an asynchronous operation. The primary way of working with promises is through a method which registers transformations from the promise's eventual value or failure reason to a new promise.

promise
Filter by
Sorted by
Tagged with
0 votes
1 answer
16 views

Javascript Promise.all call a function with .then()

I use Promise.all the trig a function after all promise are resolved. It works but I don'd understand why to call a function I havo to use an anonimus funtion and I can't call the my function directly....
Clingonboy's user avatar
-3 votes
2 answers
40 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(); ...
A. R.'s user avatar
  • 2,040
-1 votes
0 answers
30 views

Promise.resolve() as return vs simply value return in chaining

I am finding it very difficult to answer the promise chaining order question. Especially when I have return type as Promise object instead of string, I tried executing it in browser and understand ...
Sanjeet's user avatar
0 votes
0 answers
10 views

Cesium Resource Proxy getUrl with AWS SDK v3 presigned url

We are using the Cesium Resource Proxy class to provide a presigned url from s3 for each of our resources. The getUrl method must return a string and is synchronous. When using the AWS SDK v2, this ...
Novaterata's user avatar
  • 4,528
-4 votes
1 answer
42 views

Is it possible to have ongoing 120K-6M non-blocking HTTP requests getting responses after seconds and minutes? What PC limitation may prevent it? [closed]

Context: I am considering implementing a top level general backend calling various specialized backends via HTTP using non-blocking requests (using promises, futures etc.). The responses to the calls/...
Alexander Ites's user avatar
2 votes
2 answers
56 views

Do callbacks from I/O operations that return promises go to the I/O queue or the microtask queue in Node?

I'm just learning the details of how the event loop in Node works. I learned that the promise queue takes priority over the timer queue, which takes priority over the I/O queue. async function ...
J Booth's user avatar
  • 21
1 vote
1 answer
24 views

Necessary async-await working with IndexedDB

I have a react typescript App, in my App I use IndexedDB for storing some Data. I have separate class for working with IndexedDB call DB . in one of my class methods I use this code for getting all ...
Amir-s1011's user avatar
-1 votes
0 answers
10 views

NextJS | fs don't work in async function and 'use client' is involved

I'm building an app where i need to write and reading a json file constantly, doing tests with different functions and methods to work with 'fs' it doesn't work properly returning webpack errors or ...
GabFrogGo's user avatar
-1 votes
0 answers
33 views

Why is .then not working on my method chain of promises? [closed]

I am working on promises on JS, and wanted to method my chain my 3 three promises using .then. I am receiving the error: Uncaught TypeError: Cannot read properties of undefined (reading 'then') at :1:...
Yannick's user avatar
0 votes
0 answers
16 views

resolved promise stops rendering of Vue components

I use getCardsById in KanbanBoardGroup.vue to return a Promise<Card[]> but if i dont resolve it the v-for in DraggableContent wont know its a Card[] <DraggableContent v-for="card in ...
Soma Juice's user avatar
-1 votes
0 answers
14 views

nodeJS - why is promise not resolving? [duplicate]

Using nodeJS, I am trying to read the contents of a .txt file. I'm able to see the contents via 'console.log', but when I 'return data' the output is 'Promise {}'. import fs from 'node:fs/promises'; ...
Adam's user avatar
  • 1
1 vote
0 answers
19 views

How perform successive fetch() requests that build upon previous responses? [duplicate]

I apologize in advance about any obvious issues, I'm kind of fumbling my way through this at the moment and feel a bit in over my head. I'm attempting to perform a fetch request in JavaScript using an ...
EyEyRawn's user avatar
-1 votes
0 answers
22 views

Call a variable outside a Promise [duplicate]

I am working on a simple code that checks for a HTML element in Cypress. I get the element and drag it to another element, so one of its attribute changes. When it changes I take the element attribute,...
JeB's user avatar
  • 1
2 votes
1 answer
49 views

I have no idea why setTimeout wrapping promise not working as i expected

I have this code. const testArray = [1, 2, 3, 4, 5]; const test = async () => { return Promise.resolve().then(() => { console.log("Testing console log: ", new Date()); }); };...
Jaeho Lee's user avatar
  • 503
0 votes
1 answer
23 views

Promise.race for fetch tasks stops when one fetch url gives net::ERR_CONNECTION_REFUSED error

I tried to use an alternative url when one is not available but the race of promises was that the error of connection of one fetch rejected the process of another fetch. In the code you can see the ...
trzczy's user avatar
  • 1,409
1 vote
2 answers
31 views

Promise all to map or object

I have some sequalize promises. private loadFilterMetaData(): Array<Promise<any>> { const country = CatalogCountry.findAll(); const firm = CatalogFirm.findAll(); ...
Sergei Illarionov's user avatar
0 votes
0 answers
16 views

Catching stack-trace in catchAsync function

So I have my server.js like this //server.js var express = require('express'); var app = express() // Error Handler Controller const globalErrorHandler = require('./controllers/error.controller'); //...
Raul Andrade's user avatar
2 votes
1 answer
52 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(() => { ...
Roma Kim's user avatar
  • 343
0 votes
0 answers
14 views

Jquery deferred : How to use promise without Deferred for sync calls in JS [duplicate]

I need to make a sync get rest call and i dont want to deffer it, i want to get result and act upon the value for next processing. Based on input to a external api call i get a result and with the ...
Mohammed Rahamatullah's user avatar
-2 votes
1 answer
51 views

How to implement JS Promise.all without using variable captures in nested closures?

I am trying to implement JS Promise.all and this is the code that I manage to get it to work in JS: function promiseAll(promises) { var results = []; var numCompleted = 0; return new ...
Lord Yggdrasill's user avatar
0 votes
1 answer
34 views

why promise returns an unexpected output for nested promises?

I have code below and based on MDN document, I know how result and state will be specified for a promise, resulted from a handler: returns a value: p gets fulfilled with the returned value as its ...
lome1446's user avatar
1 vote
3 answers
76 views

why when I resolve a promise, the output is in pending state?

so consider the code below, when I resolve a promise the result is in pending state in the very first moment( I know after I expand the dropdown I will see the expected result but in here I'm ...
lome1446's user avatar
-1 votes
2 answers
29 views

why throw inside of an setTimeout, located inside a promise, doesn't change state and result of the output promise? [duplicate]

I know existence of a throw inside of a promise, change the state of that specific promise to rejected and the result will be the error message, but when I type this throw inside of a setTimeout ...
lome1446's user avatar
0 votes
2 answers
29 views

Fetch file, read contents and return contents all in one function [duplicate]

I have been given the task of reading a file, processing the data and returning the results. As it is an async process, I run into the problem where you cannot return from a .then, and an unresolved ...
dt1000's user avatar
  • 3,732
1 vote
1 answer
40 views

why promise has a weird precedence for errors in js?

I have the code below and I expect to first have hi in my console then the error and at the end why, but the result is: hi, then why and the last one is error, so I'm wondering, why is this happening? ...
lome1446's user avatar
2 votes
1 answer
47 views

How does nesting of promises work in javascipt [duplicate]

why does it print promise pending? I was expecting it might give promise<promise<1>> or promise<1> let k = new Promise((resolve, reject) => { let a = new Promise((res, rej) =...
Nikhil Harisinghani's user avatar
1 vote
2 answers
86 views

How can I break the for loop within the then block?

I'm new to Cypress and JavaScript. I want to create a loop that executes a request with different values until I get a certain response. let continue_loop = 1; loginLoop: for (let i = 1; i < 100; ...
Juan Carlos gularte's user avatar
0 votes
0 answers
15 views

Wait set state finishes to call another function [duplicate]

I have an useEffect where i made an api request to get data and feed an array named 'opcoes' that is declarated as a React useState. So it is something like const [opcoes, setOpcoes] = useState([]). ...
Raul Beltrame's user avatar
-2 votes
0 answers
60 views

Why do JavaScript multiple async/awaits behave differently when it awaits promises vs when it awaits functions returning promises?

I have the below code with both the implementations. const p1 = new Promise((resolve, reject) => { setTimeout(() => { resolve('promise 1'); }, 1000); }); const p2 = new Promise((...
dhanush shetty's user avatar
1 vote
0 answers
9 views

How to do computation in parallel with an S3 Node sdk call to server

I have a nodejs application which adds a raw file in an S3 bucket and also processes it. These two actions are independent but used to run in series. In order to improve the performance, I wanted to ...
alikn's user avatar
  • 11
1 vote
2 answers
86 views

Second useState doesn't update in promise chain

With React Native, this app needs to: Move an object Then update text (a number) on the screen Then move another object Then update the same text (another number) on the screen Problem: #4 does not ...
RNAppCoder's user avatar
0 votes
1 answer
26 views

Why can't I get a result from the Office.context.mailbox.item.to.getAsync function?

Writing an Outlook Add-In and trying to get the recipients from message compose mode using the Office Javascript API. I can see successful results in the console logs but I only get undefined as a ...
Amy's user avatar
  • 177
0 votes
0 answers
26 views

Type return value of function to be an array of the return values of input array of functions

I'm trying to write a method that essentially acts as a shim for Promise.allSettled, and behaves like Promise.all. The function takes in a list of Promises (whose return types may or may not be ...
Robin Wilborn's user avatar
0 votes
0 answers
23 views

angular test inside subscribe of modal

I woud like to test the code inside the subscribe of a showmodal in ngOnInit in my modal component: ngOnInit() { this.modalService.showModal.subscribe( val=>{this.modalStyle = ...
luca akenic's user avatar
0 votes
1 answer
30 views

React useEffect API Call Returning Undefined [duplicate]

I'm trying to make a fetch request to my backend API in React using UseEffect. But my data is undefined. When I console log my res.json(), I get a pending, fulfilled promise, so I think that means I'm ...
ceeb's user avatar
  • 1
0 votes
0 answers
34 views

Promise Fulfilled But Still Pending [duplicate]

I'm writing a function that sends a POST request to my backend API and returns the response as data. I need to use a POST request because I need to send information to the backend. I'm using async/...
ceeb's user avatar
  • 1
-1 votes
0 answers
25 views

Fetch and json in Angular

So fetch returns JSON and we can use .json() to extract the content as a promise. Let's say my promise is a variable named PR. How can I then extract the content of the promise and in which object ...
Rami Dhouib's user avatar
0 votes
1 answer
35 views

populate my throw object with error message in json response

I want to populate my error object {'status': response.status, 'msg': ''} with the error message present in the JSON Response of the API if there is any, otherwise throw the error object without any ...
kajezevu's user avatar
-1 votes
0 answers
33 views

Unresolved promise while redirecting to new page

My web server could return a custom exception wrapped in a 400 Bad Request object. On the client-side (Angular 9), I have something like this: return new Promise(resolve => { this.http.post(...)....
Răzvan Puștea's user avatar
0 votes
1 answer
38 views

React with Typescript Array of promises

I have the following function: function querryProposals(hash:string) { let t = api?.query.backgroundCouncil.proposalOf( hash,(data1:any)=>{ let data0 = data1....
Kazunobu Ndong's user avatar
-1 votes
0 answers
52 views

How to use JavaScript Promise Chains Smartly? [duplicate]

How can you skip a step in a promise chain if a certain condition is met, without complicating the code? function fetchData(shouldSkip) { fetch('https://api.example.com/step1') .then(response =&...
its.jaydeep's user avatar
0 votes
2 answers
40 views

How to make a recursive function type safe?

I have a component where the user can drag & drop files or folders onto it and the my code is doing something with that info. Now I got a recursive method which is traversing a folder for files ...
NineBunBun's user avatar
0 votes
0 answers
14 views

Function for IndexedDB store methods execution

I want to create async function that receive function like () => indexed_db_store.get_all() or () => indexed_db_store.get(20) and returns result of async operation: data from indexedDB. So, ...
Евгений Туровский's user avatar
-1 votes
1 answer
37 views

JavaScript Promise handlers schedule behaviour

Given this Promise chain. function getData() { return new Promise((resolve) => { // ... }) .then((data) => data.someData) .then((rawData) => processData(rawData)) .catch((...
kekerinho's user avatar
-1 votes
2 answers
35 views

Dynamic or conditional based Promise.all() and destructing

I want to get data from DB based on the boolean flag. async function main() { let promises = []; if (false) { promises.push(Promise.resolve("highlights from DB")); } if (true) {...
Ashutosh's user avatar
  • 1,037
0 votes
1 answer
62 views

ScrollTrigger.js: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'pin') GreenSock, GSAP

I inherited a project with no documentation and keep getting the error ScrollTrigger.js: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'pin') in the web console when ...
Justin's user avatar
  • 556
1 vote
0 answers
35 views

Open next tab using puppeteer

How can I open next tab upon closing existing tab? The main thing here is I have a continuasly reloading pages in executingFunctions and as soon as one of the pages has proper html, puppeteer starts ...
Mini elephant's user avatar
0 votes
0 answers
30 views

Javascript - trying to understand how promises work when using loop [duplicate]

In this example, the order of res is preserved, because await is used within a for loop, which processes each promise sequentially. This means the loop waits for the current promise to resolve before ...
CCCC's user avatar
  • 6,098
2 votes
1 answer
48 views

Linear time increase per promise when resolving concurrently using Promise.all?

I have a method that steps through a JSON payload to run computation on some data within that payload. When I create 100 promises of that method and then pass them into Promise.all(), it seems that ...
Jas Singh's user avatar
0 votes
1 answer
18 views

How do i get the pure object out of promise object when i do promise inside promise?

here is what i get in browser console and the code. I need first promise "starships" to get an array of url links, then i need second promise for "movieURLs" to get an object from ...
Danko Grgić's user avatar

1
2 3 4 5
454