Skip to content

Commit

Permalink
Remove an unnecessary Fiber.
Browse files Browse the repository at this point in the history
  • Loading branch information
glasser committed Dec 7, 2013
1 parent 6bcaaf9 commit 76bf0be
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions packages/mongo-livedata/oplog_observe_driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,30 +156,29 @@ _.extend(OplogObserveDriver.prototype, {
self._currentlyFetching = self._needToFetch;
self._needToFetch = new LocalCollection._IdMap;
var waiting = 0;
var error = null;
var anyError = null;
var fut = new Future;
Fiber(function () {
self._currentlyFetching.forEach(function (cacheKey, id) {
// currentlyFetching will not be updated during this loop.
waiting++;
self._mongoHandle._docFetcher.fetch(
self._cursorDescription.collectionName, id, cacheKey,
function (err, doc) {
if (err) {
if (!error)
error = err;
} else if (!self._stopped) {
self._handleDoc(id, doc);
}
waiting--;
if (waiting == 0)
fut.return();
});
});
}).run();
// This loop is safe, because _currentlyFetching will not be updated
// during this loop (in fact, it is never mutated).
self._currentlyFetching.forEach(function (cacheKey, id) {
waiting++;
self._mongoHandle._docFetcher.fetch(
self._cursorDescription.collectionName, id, cacheKey,
function (err, doc) {
if (err) {
if (!anyError)
anyError = err;
} else if (!self._stopped) {
self._handleDoc(id, doc);
}
waiting--;
if (waiting == 0)
fut.return();
});
});
fut.wait();
if (error)
throw error;
if (anyError)
throw anyError;
self._currentlyFetching = new LocalCollection._IdMap;
}
self._beSteady();
Expand Down

0 comments on commit 76bf0be

Please sign in to comment.