Skip to content

Instantly share code, notes, and snippets.

@nicolaslopezj
Last active October 22, 2016 05:32
Show Gist options
  • Save nicolaslopezj/f5878f8cb6f2e839daaddd163d0524c0 to your computer and use it in GitHub Desktop.
Save nicolaslopezj/f5878f8cb6f2e839daaddd163d0524c0 to your computer and use it in GitHub Desktop.
Delay all meteor publications in localhost
const lag = true;
const waitingTime = 400;
Meteor.startup(function() {
if (!lag) return;
const rootUrl = process.env.ROOT_URL;
if (rootUrl !== 'http://localhost:3000/') {
return;
} else {
console.log('Delaying all publications...');
}
_.keys(Meteor.server.publish_handlers).map(function(key) {
const func = Meteor.server.publish_handlers[key];
Meteor.server.publish_handlers[key] = function() {
this.unblock();
Meteor._sleepForMs(waitingTime + _.random(waitingTime / 3));
return func.apply(this, arguments);
};
});
Meteor.server.universal_publish_handlers = Meteor.server.universal_publish_handlers.map(function(func) {
return function() {
this.unblock();
Meteor._sleepForMs((waitingTime / 4) + _.random(waitingTime / 10));
return func.apply(this, arguments);
};
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment