Skip to content

Commit

Permalink
Minimize _noYieldsAllowed block
Browse files Browse the repository at this point in the history
Previously, observeChangesWithOplog was in it, and it can yield (if we
need to wait for the global oplog handle to be ready)
  • Loading branch information
glasser committed Dec 3, 2013
1 parent 3a73ccd commit f50f88f
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions packages/mongo-livedata/mongo_driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1139,13 +1139,13 @@ MongoConnection.prototype._observeChanges = function (
var observeKey = JSON.stringify(
_.extend({ordered: ordered}, cursorDescription));

var multiplexer, observeHandle;
var multiplexer, observeImplementation;
var firstHandle = false;

// Find a matching ObserveMultiplexer, or create a new one. This next block is
// guaranteed to not yield (and it doesn't call anything that can observe a
// new query), so no other calls to this function can interleave with it.
Meteor._noYieldsAllowed(function () {
var observeImplementation;
if (_.has(self._observeMultiplexers, observeKey)) {
multiplexer = self._observeMultiplexers[observeKey];
} else {
Expand All @@ -1158,27 +1158,32 @@ MongoConnection.prototype._observeChanges = function (
}
});
self._observeMultiplexers[observeKey] = multiplexer;
firstHandle = true;
}
});

if (self._oplogHandle && !ordered && !callbacks._testOnlyPollCallback
&& cursorSupportedByOplogTailing(cursorDescription)) {
observeImplementation = observeChangesWithOplog(
cursorDescription, self, multiplexer);
} else {
// Start polling.
observeImplementation = new MongoPollster(
cursorDescription,
self,
ordered,
multiplexer,
callbacks._testOnlyPollCallback);
}
var observeHandle = new ObserveHandle(multiplexer, callbacks);

if (firstHandle) {
if (self._oplogHandle && !ordered && !callbacks._testOnlyPollCallback
&& cursorSupportedByOplogTailing(cursorDescription)) {
// Can yield!
observeImplementation = observeChangesWithOplog(
cursorDescription, self, multiplexer);
} else {
// Start polling.
observeImplementation = new MongoPollster(
cursorDescription,
self,
ordered,
multiplexer,
callbacks._testOnlyPollCallback);
}
observeHandle = new ObserveHandle(multiplexer, callbacks);

// This field is only set for the first ObserveHandle in an
// ObserveMultiplexer. It is only there for use by one test.
if (observeImplementation)
observeHandle._observeImplementation = observeImplementation;
});
observeHandle._observeImplementation = observeImplementation;
}

// Blocks until the initial adds have been sent.
multiplexer.addHandleAndSendInitialAdds(observeHandle);
Expand Down

0 comments on commit f50f88f

Please sign in to comment.