Syntax Meteor wrapAsync

How to use Meteor wrapAsync ?

Below I am trying to do

if (tempTreatment.groupId === undefined) { // create new group Meteor.wrapAsync(Meteor.call('createTreatmentGroup', salon, tempTreatment.groupName, tempTreatment.groupName)); // get group id var getGroup = Meteor.wrapAsync(Meteor.call('getTreatmentGroup', salon, tempTreatment.groupName)); console.log(getGroup); tempTreatment.groupId = getGroup._id; } 

I want to run these two Meteor.call functions synchronously, but I get undefined on console.log(getGroup); shuold just returns an object.

+5
source share
1 answer

Meteor.wrapAsync is a server-side API designed to port Node.js asynchronous functions that require a callback as the last argument to make them display synchronously using Future s, Fibers subheadings. (more on this here: https://www.discovermeteor.com/blog/wrapping-npm-packages/ )

It is not intended to use the client side to switch the asynchronous Meteor.call to a synchronous call, because in the browser Invoke calls to the remote method are ALWAYS asynchronous.

In short, you simply cannot achieve what you are trying to do, you need to use callbacks and put the second method call into the success callback of your first method call.

+7
source

Source: https://habr.com/ru/post/984758/


All Articles