Questions tagged [promise.all]
104 questions
7
votes
1 answer
How to handle multiple mutations in parallel with react-query
I have a custom useMutation hook:
const {
status: updateScheduleStatus,
reset: updateScheduleReset,
mutateAsync: updateSchedule,
} = useUpdateSchedule(queryClient, jobId as string);
Which I understand sets up the mutation but how…

RyanP13
- 7,413
- 27
- 96
- 166
5
votes
3 answers
How to do multiple fetch requests
I would like to do multiple fetch requests with React/JavaScript, I have the following attempt which kind of works:
const fetchAll = async () => {
Promise.all([
await fetch('/api/...'),
await fetch('/api/...')
]).then(links…

salteax1
- 67
- 1
- 7
4
votes
1 answer
Promise.all() inside useEffect in react returns an array of undefined items
It works after the fetch, then after Promise.all() returns undefined. Same happens with Promise.allSettled().
function DrinksPage(props){
const [drinkCard, setDrinkCard] = useState([]);
var id = props.id;
useEffect( () =>{
…

E.K.Garcia
- 49
- 2
- 7
3
votes
4 answers
Preventing the saving of data if one fails on Promise.all - VueJS
I have two forms with data that needs to be saved using two separate post APIs. I am using Promise.all() to save all the data from these two forms at once and its working as it should. The code is as follows:
saveAll() {
Promise.all([
…

gxvr
- 296
- 2
- 17
3
votes
1 answer
Is there a way to get values of only resolved promises?
I'm calling multiple services which includes network calls and other asynchronous services in my JavaScript application.
At first I was invoking these promises one by one. In the long run it's getting hard to maintain since I'm invoking more…

Hema latha R
- 31
- 1
3
votes
3 answers
Promise.all get slowest resolving promises
I have a few hundreds of things to render in parallel in an html5 canvas. These are drawn in parallel in a Promise.all call. Now, I would like to know which of these promise is the last to be resolved.
// get a promise that will resolve in between…

ecstrema
- 543
- 1
- 5
- 20
3
votes
1 answer
Is any way to break parallel execution of the array of promises with Promise.all
I have parallel threads, and want to interrupt all unfinished thread when one of them throws an error.
But it seems that all other threads are continue to execute.
async test() {
let threads = [];
console.log('Starting threads');
try {
…

Viktor Egorov
- 61
- 3
2
votes
1 answer
Promise.all with too many fetches at a time freezes server
I bundle 115 fetch requests into a Promise.all in order to load mandatory resources. The problem is that they all fire at once and - depending on the server I test it on - either freeze the script entirely or give off a 500 error code.
I implemented…

Tim
- 71
- 6
2
votes
2 answers
Calling a promise.all with a function using dynamically generated parameters
Hello I am trying to run the same function asynchronously using different parameters but cannot figure out how to store the functions without running them before the promise all.
Here's a simplified example of what I am trying to do:
const myFunc =…

Prox Ima
- 31
- 2
2
votes
2 answers
Can I have multiple .finally() as well as multiple .catch() in Promise.all()?
var p1 = new Promise((resolve, reject) => {
resolve('p1');
});
var p2 = new Promise((resolve, reject) => {
resolve('p2');
});
Promise.all([
p1.finally(() => { console.log("p1 completed"); }),
…
user8242629
2
votes
1 answer
Push into arrays with setState - React Native
i'm new to React Native and i was working on a project using api from different url's. When i use the fetch to the url's, i want so set my state with setState but when i try it, the console.warn shows my arrays empy. What is the problem in my code?…

User 12345
- 23
- 4
2
votes
2 answers
Promises execute when defined instead of Promises.all?
I am trying to create an array of promises so I can batch promises instead of executing them all together to avoid shutting down my server. I want to execute up to 20 promises at a time.
I have written the following code:
let promises = [];
let…

Nimrod Yanai
- 777
- 2
- 8
- 30
2
votes
3 answers
fetching each item inside an array
So I'm pretty sure this have something to do with Promise.all or something like that but I'm not sure how to do it. will appreciate if someone can help me out with this code.
Note: the array I'm trying to map is an array of objects if that…

Ni Tai
- 499
- 1
- 7
- 13
2
votes
1 answer
Javascript Promise.all() inside of a loop
I am trying to make a web API call twice inside of a loop, then wait until the webAPI has returned before pushing the returned values as a subarray within a larger array. Here's my code:
var latlngPairs = [];
function extractLatLongPairs(jsonobj){
…

Sanoris
- 23
- 3
2
votes
1 answer
Typescript - dynamic array of promises with different return values
Can anyone help me solve what's wrong with this code?
I can't find the right type to put in that Promise.all call at the bottom.
it tried also Promise.all(ops) but PullRequests[] can't be optional...
function…

Itamar Gronich
- 193
- 10