Meteor build delay in iteration through collection


#1

Hello

I have created a stackoverflow topic, but i have yet no solution.
The problem is i have in my db many documents and i want iterate it and for each row i want
build some delay based on the duration-field of the actually processed collection.
Then for the next collection the same process with delay.

Here is the orginal question: http://stackoverflow.com/questions/38804301/meteor-delay-in-iteration-through-collection?noredirect=1#comment64980427_38804301

With Meteor._sleepForMs(data[i].duration*1000); for the first collections it delays correctly, but then it has a unexpected behaviour with different delays.

Also the solution with fibers doesn’t process correctly.

Meteor.methods({

start: function() {
let data = Strategy.find({}, {limit: 5}).fetch();
for (let i = 0; i < data.length; ++i) {
mqttClient.publish(“test”, data[i].charge);
Meteor._sleepForMs(data[i].duration*1000);
}
}