lvlpurple/mubsub — pull request #1 by 117nord (2013-12-13 18:57:41+00:00)
Title: Fix duplicated events

This started when we discovered that not exiting on a broken cursor error could result in duplicated events.

We also wanted to be able to get old events when initializing a channel, this became the backlog.

I also fixed the problem caused by the fact that mongo ObjectIDs are not strictly increasing over time. The fact that the startup of mubsug relied on a $gt condition based on the last document of the collection could cause listeners to miss events. This is handled by "prerolling", starting before the target document and walking the cursor until the target document is encountered.

Also added a sync lost error. This error is emitted when mubsub detects that it may have missed events. This can be caused by writing to the event collection too fast compared to listeners and overwriting the listeners cursor position. It can happen if you use a small collection size. Or if a listening process is disconnected too long from the database.

Error handling is also changed, all handled errors are no longer emitted. The exception is the "Mubsub: sync lost" error which is emitted and handled. It is handled in the sense that mubsub will continue to emit new events but it indicates some events may have been missed. So the caller will be notified and can choose if this is a fatal error or not.