|
|
@ -1,6 +1,7 @@
|
|
|
|
use std::iter::Iterator;
|
|
|
|
use std::iter::Iterator;
|
|
|
|
use std::ptr;
|
|
|
|
use std::ptr;
|
|
|
|
use std::thread;
|
|
|
|
use std::thread;
|
|
|
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
|
|
|
|
use mongoc::bindings;
|
|
|
|
use mongoc::bindings;
|
|
|
|
use bson::{Bson,Document,oid};
|
|
|
|
use bson::{Bson,Document,oid};
|
|
|
@ -25,7 +26,7 @@ pub struct Cursor<'a> {
|
|
|
|
_created_by: CreatedBy<'a>,
|
|
|
|
_created_by: CreatedBy<'a>,
|
|
|
|
inner: *mut bindings::mongoc_cursor_t,
|
|
|
|
inner: *mut bindings::mongoc_cursor_t,
|
|
|
|
tailing: bool,
|
|
|
|
tailing: bool,
|
|
|
|
tail_wait_time_ms: u32,
|
|
|
|
tail_wait_duration: Duration,
|
|
|
|
// Become owner of bsonc because the cursor needs it
|
|
|
|
// Become owner of bsonc because the cursor needs it
|
|
|
|
// to be allocated for it's entire lifetime
|
|
|
|
// to be allocated for it's entire lifetime
|
|
|
|
_fields: Option<bsonc::Bsonc>
|
|
|
|
_fields: Option<bsonc::Bsonc>
|
|
|
@ -42,7 +43,7 @@ impl<'a> Cursor<'a> {
|
|
|
|
_created_by: created_by,
|
|
|
|
_created_by: created_by,
|
|
|
|
inner: inner,
|
|
|
|
inner: inner,
|
|
|
|
tailing: false,
|
|
|
|
tailing: false,
|
|
|
|
tail_wait_time_ms: 0,
|
|
|
|
tail_wait_duration: Duration::from_millis(0),
|
|
|
|
_fields: fields
|
|
|
|
_fields: fields
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -104,7 +105,7 @@ impl<'a> Iterator for Cursor<'a> {
|
|
|
|
if self.tailing && self.is_alive() {
|
|
|
|
if self.tailing && self.is_alive() {
|
|
|
|
// Since there was no error, this is a tailing cursor
|
|
|
|
// Since there was no error, this is a tailing cursor
|
|
|
|
// and the cursor is alive we'll wait before trying again.
|
|
|
|
// and the cursor is alive we'll wait before trying again.
|
|
|
|
thread::sleep_ms(self.tail_wait_time_ms);
|
|
|
|
thread::sleep(self.tail_wait_duration);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// No result, no error and cursor not tailing so we must
|
|
|
|
// No result, no error and cursor not tailing so we must
|
|
|
@ -193,7 +194,7 @@ impl<'a> Iterator for TailingCursor<'a> {
|
|
|
|
self.cursor = match self.collection.find(&self.query, Some(&self.find_options)) {
|
|
|
|
self.cursor = match self.collection.find(&self.query, Some(&self.find_options)) {
|
|
|
|
Ok(mut c) => {
|
|
|
|
Ok(mut c) => {
|
|
|
|
c.tailing = true;
|
|
|
|
c.tailing = true;
|
|
|
|
c.tail_wait_time_ms = self.tail_options.wait_time_ms;
|
|
|
|
c.tail_wait_duration = self.tail_options.wait_duration;
|
|
|
|
Some(c)
|
|
|
|
Some(c)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Err(e) => return Some(Err(e.into()))
|
|
|
|
Err(e) => return Some(Err(e.into()))
|
|
|
|