TonyGen/mongoDB-haskell — pull request #11 by mkscrg (2011-12-12 22:20:20+00:00)
Title: Fix for issue #10

See (issue #10)[https://github.com/TonyGen/mongoDB-haskell/issues/10].

`Database.MongoDB.Query.next` prefetches a promise of the next batch of documents from the server whenever it has exhausted its current batch. The following call to `next` fulfills that promise (thereby turning it into a concrete batch of documents) and then acts on it. When the batch has zero results, the old behavior was this:

> If the cursor ID is zero, return a dead Batch. Otherwise, raise an exception.

It is normal for the server to send empty batches with nonzero cursor IDs when using tailable cursors, so a change was required to allow the use of tailable cursors. The new behavior when an empty batch is encountered is this:

> If the cursor ID is zero, return a dead Batch. Otherwise, get a fresh batch from the server and act normally on it. (Only get a fresh batch once per call to `next`.)

This new behavior does not affect the performance of `next`, except when calling it repeatedly on a tailable cursor with no new data. In those (generally avoidable) cases, each call to `next` results in two server calls instead of one.