Help with setInterval executed in metero.call


#1

try to execute the following meteor.call, located on the server side

Meteor.call(“bucle”)
.
.
Meteor.methods({

bucle: function() {
mySandwich(function (con) {
var x = 0,
y = 0,
z = 0;
setInterval(function() {
if (x < con.length){
mySandwich2(con[x].woeid,function(td) {
Twit.post(‘statuses/update’, {status: td }, function(error, data,response){
if(!error){
y=0;
}else{
y=0;
}
});
})
}
if(x===con.length){
x=0;
}
x++
}, 9000)
})
}

when I logging on twitter and execute the call works, but if I logging with a different account and invoke the call from another web client, stops execution of the setInterval he was doing and run the new invoking, that happens or I am doing wrong? I run several setInterval invoking the call


#2

Just a thought: did your try Meteor.setInterval instead of setInterval?


#3

i try with Meteor.setInterval but but I have the following error.

Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.

at Object.Meteor.nodeCodeMustBeInFiber (packages/meteor/dynamics_nodejs.js:9:1)
at [object Object].
.extend.get (packages/meteor/dynamics_nodejs.js:21:1)
at withoutInvocation (packages/meteor/timers.js:4:1)
at bindAndCatch (packages/meteor/timers.js:13:1)
at Object._.extend.setInterval (packages/meteor/timers.js:40:1)
at trendmedia.js:182:26
at [object Object]._onTimeout (trendmedia.js:283:30)
at Timer.listOnTimeout [as ontimeout] (timers.js:121:15)


#4

Meteor does not allow use async function in server side. You need use Meteor.wrapAsync to wrap this to be a sync func:

Twit.post('statuses/update', { status: td }, function(error, data, response) {
    if (!error) {
        y = 0;
    } else {
        y = 0;
    }
});


#5

It does, in a manner of speaking.

const Future = Npm.require('fibers/future');
Meteor.methods({
  doTheThing: function (waitTime) {
    let future = new Future();
    Meteor.setTimeout(future.return, 50000);
    return future.wait();
  }
});

#6

meteor.setinterval to make the change but the problem that opened this post I still happening