Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sleep trait #665

Merged
merged 12 commits into from
Dec 6, 2017
235 changes: 125 additions & 110 deletions src/executor/current_thread.rs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub mod current_thread;
#[cfg(feature = "use_std")]
mod enter;

#[cfg(feature = "use_std")]
mod sleep;

#[allow(deprecated)]
#[cfg(feature = "use_std")]
pub use task_impl::{Unpark, Executor, Run};
Expand All @@ -26,3 +29,6 @@ pub use self::current_thread::CurrentThread;

#[cfg(feature = "use_std")]
pub use self::enter::{enter, Enter};

#[cfg(feature = "use_std")]
pub use self::sleep::{Sleep, Wakeup};
22 changes: 22 additions & 0 deletions src/executor/sleep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::time::Duration;

/// Puts the current thread to sleep.
pub trait Sleep {
/// Wake up handle.
type Wakeup: Wakeup;

/// Get a new `Wakeup` handle.
fn wakeup(&self) -> Self::Wakeup;

/// Put the current thread to sleep.
fn sleep(&mut self);

/// Put the current thread to sleep for at most `duration`.
fn sleep_timeout(&mut self, duration: Duration);
}

/// Wake up a sleeping thread.
pub trait Wakeup: Send + Sync + 'static {
/// Wake up the sleeping thread.
fn wakeup(&self);
}
Loading