Last active
October 22, 2016 05:32
-
-
Save nicolaslopezj/f5878f8cb6f2e839daaddd163d0524c0 to your computer and use it in GitHub Desktop.
Delay all meteor publications in localhost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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