I'm implementing PubSub using MongoDB. If I create my query specifying a TailableCursor with NoCursorTimeout:
using(var enumerator = _Collection.FindAs<BsonDocument>(Query.GTE("CreationTimeUTC", DateTime.UtcNow))
.SetFlags(QueryFlags.AwaitData | QueryFlags.NoCursorTimeout | QueryFlags.TailableCursor)
.SetSortOrder(SortBy.Ascending("$natural")).GetEnumerator))
{
while(true)
{
if(enumerator.MoveNext())
{
//process the message here
}
}
}
MoveNext() blocks indefinitely (or until data is available or an error occurs). If I want to force MoveNext() to return (for instance, if I want to cancel listening) how do I do it? Call Dispose() on the enumerator or the cursor?