Permalink
Browse files

New helper Meteor._noYieldsAllowed: ensures that a section of code do…

…es not yield.
  • Loading branch information...
1 parent ead2a14 commit ea4d04c58b5d1ecfa7c3d19966c7217f0e9e9795 @glasser glasser committed Nov 10, 2012
Showing with 17 additions and 0 deletions.
  1. +16 −0 packages/meteor/fiber_helpers.js
  2. +1 −0 packages/meteor/package.js
@@ -0,0 +1,16 @@
+Meteor._noYieldsAllowed = function (f) {
+ // "Fiber" and "yield" are both in the global namespace. The yield function is
+ // at both "yield" and "Fiber.yield". (It's also at require('fibers').yield
+ // but that is because require('fibers') === Fiber.)
+ var savedYield = Fiber.yield;
+ Fiber.yield = function () {
+ throw new Error("Can't call yield in a noYieldsAllowed block!");
+ };
+ global.yield = Fiber.yield;
+ try {
+ return f();
+ } finally {
+ Fiber.yield = savedYield;
+ global.yield = savedYield;
+ }
+};
@@ -34,6 +34,7 @@ Package.on_use(function (api, where) {
api.add_files('server_environment.js', 'server');
api.add_files('helpers.js', ['client', 'server']);
api.add_files('timers.js', ['client', 'server']);
+ api.add_files('fiber_helpers.js', 'server');
// dynamic variables, bindEnvironment
// XXX move into a separate package?

0 comments on commit ea4d04c

Please sign in to comment.