Exit callback containing continuous data stream

Hi guys,

I have a callback with a continuous data stream. This callback is inside a meteor method.

Meteor.methods({
  'some_method', function() {
     externalApi.method(parameter, Meteor.bindEnvironment(function(p1, p2){
        //here i parse the data and insert it into the collection
       //How can I get out of here?
     })
   }
})

I use Meteor.bindEnvironment because the response comes from 5 sensors, simultaneous.

Are you shure you need the environment there? Are you going to return some data from the some_method? If so, then just use Fibers or some package like sync-methods

No. But i want to be able to exit the callback, so that I can change the sensors.
Example:
User chooses either 1,2 or all 5 sensors on which to listen to ->
clicks on “get data” button ->
‘some_method’ is called server-side ->
client gets data received via collections ->
client can be able to stop the data stream so that he can either exit or change the setup (credentials, etc) ->
client clicks in “get data” button ->…
Problem is that the server-side gets ‘blocked’ by executing the ‘some_method’ and keeps listening and parsing the data from the callback.

Got you! I ve had relevant issue. It is better to make a “stream” as Meteor pub/sub as you mentioned and just try to call this.unblock() inside the some_method. Also I gues you should handle stop action for your ``externalApi```?

I would probably create separate collection which will work as requested state. It would have configuration per user and on added/removed/changed observed calls it would access that external API object and modify settings.

Than calls would consist of modifying this collection.

Well see, my external api doesn’t have an unsubscribe from the data flow… So I’ll to exist the callback by myself.
I’ll try with this.unblock() and I’ll let you know what happens