I have a Meteor server method that executes a function that I want to run in the background. I want the server method to continue while the function runs in a different process.
the method:
myMethod: function(arg) {
_event.emit("myEvent",args);
...do some other stuff
}
I'd like the server to do the other stuff and return to the client, and to do the stuff in _event.emit in the background no results have to be sent back to the client.
What it currently does is run the stuff in _event.emit and than the other stuff and then return to the client.
I tried to solve it by doing a call on server side with an empty callback function, but that didn't do the trick
myMethod: function (arg) {
return Meteor.call("secondMethod", _.toArray(arg), function() {})
}
secondMethod: function (arg) {
_event.emit("myEvent",args);
}
hope someone knows a solution for this. thanks
On the server you can just use Meteor.setTimeout() to run a function asynchronously. Just use an interval of zero if you want to return control immediately. Your main function will continue to run and as soon as there's nothing left in the event queue the scheduled task will run (or it will wait the amount of time you specify if non-zero).