Commit b2b310fe authored by Ralf's avatar Ralf
Browse files

cargo fmt

parent e76cfc7c
...@@ -10,4 +10,3 @@ pub enum Event { ...@@ -10,4 +10,3 @@ pub enum Event {
Buzz, Buzz,
UserCommand, UserCommand,
} }
...@@ -18,25 +18,24 @@ struct ThreadState { ...@@ -18,25 +18,24 @@ struct ThreadState {
} }
pub trait SpawnWakeable<'a> { pub trait SpawnWakeable<'a> {
fn spawn_wakeable<F>(&self, f: F) where fn spawn_wakeable<F>(&self, f: F) where F: FnOnce(WakeableThread) + Send + 'a;
F: FnOnce(WakeableThread) + Send + 'a;
} }
impl<'a> SpawnWakeable<'a> for Scope<'a> { impl<'a> SpawnWakeable<'a> for Scope<'a> {
fn spawn_wakeable<F>(&self, f: F) where fn spawn_wakeable<F>(&self, f: F)
F: FnOnce(WakeableThread) + Send + 'a where F: FnOnce(WakeableThread) + Send + 'a
{ {
let state = Arc::new(ThreadState { let state = Arc::new(ThreadState {
mutex: Mutex::new(ShouldThreadRun::Yes), mutex: Mutex::new(ShouldThreadRun::Yes),
cond: Condvar::new(), cond: Condvar::new(),
}); });
let thread = WakeableThread { state: state.clone() }; let thread = WakeableThread { state: state.clone() };
self.spawn(move || f(thread) ); self.spawn(move || f(thread));
// Now defer the action that we want to wake up this thread. // Now defer the action that we want to wake up this thread.
// This will be executed *before* the join deferred by spawn. // This will be executed *before* the join deferred by spawn.
self.defer(move || { self.defer(move || {
// We panic if the lock is poisened, which only happens if someone paniced // We panic if the lock is poisened, which only happens if someone paniced
let mut should_run = state.mutex.lock().unwrap(); let mut should_run = state.mutex.lock().unwrap();
......
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