Comprehending Async.runSync Callback

I am trying to use Async.runSync. The example in the documentation is… terse. Since waiting for a given time, why use the function at all in such a scenario other than for an example.

What I am trying to do is set the value of a variable to the return result of a method within the parent object, the sibling method being called is an external API call. The very next statement in the method requires the returned value.

Currently, the sibling returns an array. The broken code that I want to work is as follows:

var array = this.getArrayFromAPI();
var string = array[array.length - 1];

I do not want to create a huge callback chain at this point in the code. Therefore, I am thinking runAsync should work but I do not quite understand how to trigger it properly. I modified myFriends to take a function for a parameter, and return it with:

return callback (error, array);

My theory is:

var array = Async.runSync (this.getArrayFromAPI(done));

or perhaps:

var array = Async.runSync ( function (done) {
    return self.getArrayFromAPI (done);
});

I don’t usually use forums, but … saw the tweet and thought I’d check it out…and just happened to have a problem at the time! :smile:

Thanks in advance,
iDM

Since at least Meteor 3 (probably a lot earlier), Async is no longer available. The usual async/await API is available.
I have not seen anything about this API in the codebase. If it came from a package then I need to know what package it is, to be able to help here.


I have looked into this question as part of my help desk series, if you like what I’m doing please sponsor me.