1
votes

I have a Meteor client-side asynchronous call that I can't seem to get a return value from. I know I can't use futures on the client-side, so I'm stuck.

And since the Meteor.call() is from the client-side, it has to be asynchronous. It looks like this:

Meteor.call('DirList', path, function(error, result) { console.log(result); });

The console.log() works fine, but how do I get the result back into the surrounding function?

Bob

1

1 Answers

2
votes

You can store the result in a Session variable and then do the logic with the variable inside a Deps.autorun context. Like:

Meteor.call('DirList', path, function(error, result) { Session.set('result', result); });
Deps.autorun(function (c) {
  var result = Session.get('result');
  if (!result) return;
  c.stop();
  alert(result);
});