code: function (f) {                                                                 // 1513
      var self = this;                                                                                              // 1514
      var runFAfterUpdates = function () {                                                                          // 1515
        self._afterUpdateCallbacks.push(f);                                                                         // 1516
      };                                                                                                            // 1517
      var unflushedServerDocCount = 0;                                                                              // 1518
      var onServerDocFlush = function () {                                                                          // 1519
        --unflushedServerDocCount;                                                                                  // 1520
        if (unflushedServerDocCount === 0) {                                                                        // 1521
          // This was the last doc to flush! Arrange to run f after the updates                                     // 1522
          // have been applied.                                                                                     // 1523
          runFAfterUpdates();                                                                                       // 1524
        }                                                                                                           // 1525
      };                                                                                                            // 1526
      _.each(self._serverDocuments, function (collectionDocs) {                                                     // 1527
        collectionDocs.forEach(function (serverDoc) {                                                               // 1528
          var writtenByStubForAMethodWithSentMessage = _.any(                                                       // 1529
            serverDoc.writtenByStubs, function (dummy, methodId) {                                                  // 1530
              var invoker = self._methodInvokers[methodId];                                                         // 1531
              return invoker && invoker.sentMessage;                                                                // 1532
            });                                                                                                     // 1533
          if (writtenByStubForAMethodWithSentMessage) {                                                             // 1534
            ++unflushedServerDocCount;                                                                              // 1535
            serverDoc.flushCallbacks.push(onServerDocFlush);                                                        // 1536
          }                                                                                                         // 1537
        });                                                                                                         // 1538
      });                                                                                                           // 1539
      if (unflushedServerDocCount === 0) {                                                                          // 1540
        // There aren't any buffered docs --- we can call f as soon as the current                                  // 1541
        // round of updates is applied!                                                                             // 1542
        runFAfterUpdates();                                                                                         // 1543
      }                                                                                                             // 1544
    }
docs: 1508 1509 Ensures that "f" will be called after all documents currently in                                             // 1510 _serverDocuments have been written to the local cache. f will not be called                                  // 1511 if the connection is lost before then!                                                                       // 1512