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] [dependencies]
libc = "*" libc = "*"
log = "*" log = "*"
bson = "*"
[dependencies.bson]
git = "https://github.com/zonyitoo/bson-rs.git"
[dependencies.mongoc-sys] [dependencies.mongoc-sys]
path = "mongoc-sys" path = "mongoc-sys"

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

@ -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()))

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

Loading…
Cancel
Save