The problem with this approach is that getProfile is blocking getComments and getFriends. Once getProfile is resolved successfully, getComments runs and blocking getFriends. When getComments is resolved successfully, getFriends finally runs.
That is not the same thing as running them parallel. That is more like the following:
Yeah, promise.all wont resolve with a single reject, so what I would do is return an error as a normal result instead of rejecting, and then filter out errors after promises finish. Until they make something like .every available for .all as well.
And while it might be strange to have errors passing into resolve, as long as your code is expecting them, I see nothing wrong in it.
const result = await Promise.all([
getProfile(this.id),
getComments(this.id),
getFriends(this.id),
]);
However, this waits for all to finish and does not replace the first I descried, as I see it?
As I see it the only way to avoid this with async/await is to wrap the promises into their own function and run it in Promise.all. Like this (haven't tested this yet):
Hi,
As I see it, in both cases the inner methods run async and the end promise is awaited so it would not be blocking the current thread anyway.
When I get time, will execute 2nd e.g. but highly doubt if it has any difference in behavior compared to 1st.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The problem with this approach is that getProfile is blocking getComments and getFriends. Once getProfile is resolved successfully, getComments runs and blocking getFriends. When getComments is resolved successfully, getFriends finally runs.
That is not the same thing as running them parallel. That is more like the following:
Ah sorry, I didn't read it correctly.
Yeah, promise.all wont resolve with a single reject, so what I would do is return an error as a normal result instead of rejecting, and then filter out errors after promises finish. Until they make something like .every available for .all as well.
And while it might be strange to have errors passing into resolve, as long as your code is expecting them, I see nothing wrong in it.
Hey, so for your particular use case, I would try this:
Here is a working proof of concept:
To run them parallel there is this approach:
However, this waits for all to finish and does not replace the first I descried, as I see it?
As I see it the only way to avoid this with async/await is to wrap the promises into their own function and run it in Promise.all. Like this (haven't tested this yet):
Hi,
As I see it, in both cases the inner methods run async and the end promise is awaited so it would not be blocking the current thread anyway.
When I get time, will execute 2nd e.g. but highly doubt if it has any difference in behavior compared to 1st.