Commit e0bed0a2 authored by Ralf's avatar Ralf
Browse files

cargo fmt

parent 7a20cf34
......@@ -76,8 +76,7 @@ impl State for OpenState {
if let Event::Bell(true) = ev {
buzzer.spawn(Duration::from_secs(2));
}
})
);
}));
actors.buzz = buzzer.terminate();
if r == EventsResult::ShuttingDown {
return None;
......@@ -85,4 +84,3 @@ impl State for OpenState {
None // FIXME
}
}
......@@ -21,37 +21,39 @@ enum WakeableState<T> {
pub struct WakeableHandle<T, F> {
w_state: WakeableState<T>, // invariant: This is never empty when control is to the user
fun: Arc<F>
fun: Arc<F>,
}
pub struct WakeableThread {
state: Arc<ThreadState>,
}
pub fn prepare_wakeable<D, F, T>(t: T, f: F) -> WakeableHandle<T, F> where
D: Send + 'static,
pub fn prepare_wakeable<D, F, T>(t: T, f: F) -> WakeableHandle<T, F>
where D: Send + 'static,
T: Send + 'static,
F: Fn(WakeableThread, T, D) -> T + Send + Sync + 'static
{
WakeableHandle { w_state: WakeableState::Lazy(t), fun: Arc::new(f) }
WakeableHandle {
w_state: WakeableState::Lazy(t),
fun: Arc::new(f),
}
}
pub fn spawn_wakeable<D, F, T>(t: T, d: D, f: F) -> WakeableHandle<T, F> where
D: Send + 'static,
pub fn spawn_wakeable<D, F, T>(t: T, d: D, f: F) -> WakeableHandle<T, F>
where D: Send + 'static,
T: Send + 'static,
F: Fn(WakeableThread, T, D) -> T + Send + Sync + 'static,
F: Fn(WakeableThread, T, D) -> T + Send + Sync + 'static
{
let mut handle = prepare_wakeable(t, f);
handle.spawn(d);
handle
}
impl<T, F> WakeableHandle<T, F>
{
pub fn spawn<D>(&mut self, d: D) where
D: Send + 'static,
impl<T, F> WakeableHandle<T, F> {
pub fn spawn<D>(&mut self, d: D)
where D: Send + 'static,
T: Send + 'static,
F: Fn(WakeableThread, T, D) -> T + Send + Sync + 'static,
F: Fn(WakeableThread, T, D) -> T + Send + Sync + 'static
{
// get ahand of the t, wherever it is
let t = self.get_t();
......@@ -77,7 +79,7 @@ impl<T, F> WakeableHandle<T, F>
WakeableState::Running(handle, state) => {
state.wakeup();
handle.join().unwrap() // panics only if the thread paniced
},
}
WakeableState::Empty => panic!("The WakeableState can not be empty"),
}
}
......@@ -90,12 +92,12 @@ impl<T, F> WakeableHandle<T, F>
impl<T, F> Drop for WakeableHandle<F, T> {
fn drop(&mut self) {
match self.w_state {
WakeableState::Empty => {}, // all right, the user called "terminate"
WakeableState::Lazy(_) => {}, // we were never used :( TODO: emit a warning?
WakeableState::Empty => {} // all right, the user called "terminate"
WakeableState::Lazy(_) => {} // we were never used :( TODO: emit a warning?
WakeableState::Running(_, ref state) => {
// the thread could still be running. emit a warning? Also, speed up the shutdown
state.wakeup();
},
}
};
}
}
......
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