Commit 9058fa27 authored by Ralf's avatar Ralf
Browse files

make Wakeable actually spawn a thread

parent fce6522e
use std::time::Duration; use std::time::Duration;
use std::sync; use std::sync;
use std::thread;
pub struct Wakeable<T> { pub struct Wakeable<T> {
t: T, join: thread::JoinHandle<T>,
} }
pub struct Thread; pub struct Thread;
...@@ -10,11 +11,11 @@ impl<T: Send + 'static> Wakeable<T> { ...@@ -10,11 +11,11 @@ impl<T: Send + 'static> Wakeable<T> {
pub fn new<F>(f: F) -> Self pub fn new<F>(f: F) -> Self
where F: FnOnce(Thread) -> T + Send + 'static where F: FnOnce(Thread) -> T + Send + 'static
{ {
Wakeable { t: f(Thread) } Wakeable { join: thread::spawn(|| f(Thread)) }
} }
pub fn terminate(self) -> T { pub fn terminate(self) -> T {
self.t self.join.join().unwrap() // If the child thread paniced, so do we
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment