Async Calls in Meteor 3

Hi,

need a bit of help here. I am not sure I understand why the first is wrong but the second is right.

They are both async calls followed by .then()
Thank you.

Why isn’t the first one ok? What behavior are you seeing?

Off-topic, but Promise.all and the usage at the bottom are not the same thing. Requests in Promise.all are executed almost simultaneously, and if one fails, it doesn’t matter if the others succeed or fail. In the bottom usage, the promise requests are executed in order. In some cases it may be necessary to do async/await operations in an array and add something to the data, for this I use “GitHub - sindresorhus/p-map: Map over promises concurrently”. I also recommend you to look at these. GitHub - sindresorhus/promise-fun: Promise packages, patterns, chat, and tutorials

ok … but this is my question :)). In the migration document, and you can also see in the image, that is commented as “This is not ok”. I am seeing no wrong behavior and I use that everywhere in my client side.

Ah I didn’t realize you pulled those examples from the migration docs. :slightly_smiling_face: Honestly, that part of the docs seems like it could use another pass to clarify and add some more detail.

I would think this one would be ok:

Meteor.callAsync('someMethod')
  .then(data => console.log(data))
  .catch(err => console.log(err));

Hopefully @denyhs or @nachocodoner can shed some light.

Perhaps the point there is not to run two method calls in parallel. If that is the problem, then running a single then call is fine, but running two at the same time is not. We might need to research implementing a queueing/batching mechanism that either forces it to run on call at a time behind the scenes, or sends multiple requests at the same time gracefully.

I wrote this for @helenejs/data to work around update conflicts within the same memory collection.

Is this still the current status?

Previously, this was the case ONLY when the methods had stubs.

Then, later on, there was a fix recommended by @zodern: Proposal to fix issues with async method stubs

So what is the status now?

Now that you mention a queueing solution, didn’t zodern’s queuing solution already get implemented? :slightly_smiling_face:

I think a lot of that part of the docs is outdated as zodern indicated here: Meteor 3 Migration Guide Feedback · Issue #13109 · meteor/meteor · GitHub

This goes deeper than I initially thought and apparently there is already a solution:

I will try to understand this some more, not entirely sure about the macrotasks part.

Ok, I take it the documentation is wrong or incomplete, useless or outdated … I mean unusable. I am considering to take a paid consultation to find out whether the documentation is right or wrong and how I should write a function in Meteor 3.

We are going to review and fix it, already added it to our queue.

1 Like

I don’t think the document is correct anymore in this case. I’ll take time today to retest everything in this section and update it.

4 Likes