wakeable.rs 440 Bytes
Newer Older
Ralf's avatar
Ralf committed
1 2 3
use std::time::Duration;
use std::sync;

Constantin Berhard's avatar
Constantin Berhard committed
4 5
pub struct Wakeable<T> {
    t: T,
Ralf's avatar
Ralf committed
6
}
Constantin Berhard's avatar
Constantin Berhard committed
7
pub struct Thread;
Ralf's avatar
Ralf committed
8 9

impl<T: Send + 'static> Wakeable<T> {
Constantin Berhard's avatar
Constantin Berhard committed
10
    pub fn new<F>(f: F) -> Self
Ralf's avatar
Ralf committed
11 12
        where F: FnOnce(Thread) -> T + Send + 'static
    {
Constantin Berhard's avatar
Constantin Berhard committed
13
        Wakeable { t: f(Thread) }
Ralf's avatar
Ralf committed
14
    }
Constantin Berhard's avatar
Constantin Berhard committed
15 16

    pub fn terminate(self) -> T {
Ralf's avatar
Ralf committed
17 18 19 20 21
        self.t
    }
}

impl Thread {
Ralf's avatar
Ralf committed
22
    pub fn sleep(&self, _: Duration) -> sync::WaitTimeoutResult {
Ralf's avatar
Ralf committed
23 24 25
        unimplemented!()
    }
}