Use durations instead of ms for sleeps

pull/4/head
Thijs Cadier 9 years ago
parent 9a65732c26
commit 269d26feb9

@ -14,9 +14,7 @@ name = "tests"
[dependencies]
libc = "*"
log = "*"
[dependencies.bson]
git = "https://github.com/zonyitoo/bson-rs.git"
bson = "*"
[dependencies.mongoc-sys]
path = "mongoc-sys"

@ -1,6 +1,7 @@
use std::ptr;
use std::ffi::CStr;
use std::borrow::Cow;
use std::time::Duration;
use mongoc::bindings;
use bsonc;
@ -138,14 +139,14 @@ impl UpdateOptions {
}
pub struct TailOptions {
pub wait_time_ms: u32,
pub max_retries: u32
pub wait_duration: Duration,
pub max_retries: u32
}
impl TailOptions {
pub fn default() -> TailOptions {
TailOptions {
wait_time_ms: 500,
wait_duration: Duration::from_millis(500),
max_retries: 5
}
}

@ -1,6 +1,7 @@
use std::iter::Iterator;
use std::ptr;
use std::thread;
use std::time::Duration;
use mongoc::bindings;
use bson::{Bson,Document,oid};
@ -22,13 +23,13 @@ pub enum CreatedBy<'a> {
}
pub struct Cursor<'a> {
_created_by: CreatedBy<'a>,
inner: *mut bindings::mongoc_cursor_t,
tailing: bool,
tail_wait_time_ms: u32,
_created_by: CreatedBy<'a>,
inner: *mut bindings::mongoc_cursor_t,
tailing: bool,
tail_wait_duration: Duration,
// Become owner of bsonc because the cursor needs it
// to be allocated for it's entire lifetime
_fields: Option<bsonc::Bsonc>
_fields: Option<bsonc::Bsonc>
}
impl<'a> Cursor<'a> {
@ -39,11 +40,11 @@ impl<'a> Cursor<'a> {
) -> Cursor<'a> {
assert!(!inner.is_null());
Cursor {
_created_by: created_by,
inner: inner,
tailing: false,
tail_wait_time_ms: 0,
_fields: fields
_created_by: created_by,
inner: inner,
tailing: false,
tail_wait_duration: Duration::from_millis(0),
_fields: fields
}
}
@ -104,7 +105,7 @@ impl<'a> Iterator for Cursor<'a> {
if self.tailing && self.is_alive() {
// Since there was no error, this is a tailing cursor
// 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;
} else {
// No result, no error and cursor not tailing so we must
@ -192,8 +193,8 @@ impl<'a> Iterator for TailingCursor<'a> {
// Set the cursor
self.cursor = match self.collection.find(&self.query, Some(&self.find_options)) {
Ok(mut c) => {
c.tailing = true;
c.tail_wait_time_ms = self.tail_options.wait_time_ms;
c.tailing = true;
c.tail_wait_duration = self.tail_options.wait_duration;
Some(c)
},
Err(e) => return Some(Err(e.into()))

@ -1,5 +1,6 @@
use std::sync::Arc;
use std::thread;
use std::time::Duration;
use bson;
@ -79,7 +80,7 @@ fn test_tailing_cursor() {
});
// Wait for the thread to boot up
thread::sleep_ms(250);
thread::sleep(Duration::from_millis(250));
// Insert some more documents into the collection
for _ in 0..25 {

Loading…
Cancel
Save