Minor style improvements
This commit is contained in:
parent
4eeb280f0d
commit
e569bdb416
2 changed files with 15 additions and 22 deletions
|
|
@ -36,26 +36,20 @@ impl Future for TimerFuture {
|
||||||
type Output = ();
|
type Output = ();
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
if matches!(*state, State::Completed) {
|
match *state {
|
||||||
return Poll::Ready(());
|
State::Completed => return Poll::Ready(()),
|
||||||
}
|
State::NotStarted(duration) => {
|
||||||
|
|
||||||
if let State::NotStarted(duration) = *state {
|
|
||||||
let thread_state = self.state.clone();
|
let thread_state = self.state.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
thread::sleep(duration);
|
thread::sleep(duration);
|
||||||
let mut state = thread_state.lock().unwrap();
|
let mut state = thread_state.lock().unwrap();
|
||||||
let waker = if let State::Running(waker) = &*state {
|
if let State::Running(waker) = std::mem::replace(&mut *state, State::Completed) {
|
||||||
Some(waker.clone())
|
waker.wake();
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
};
|
||||||
*state = State::Completed;
|
|
||||||
if let Some(w) = waker {
|
|
||||||
w.wake();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
State::Running(_) => {}
|
||||||
|
};
|
||||||
|
|
||||||
*state = State::Running(cx.waker().clone());
|
*state = State::Running(cx.waker().clone());
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,7 @@ impl<L: 'static, B: 'static, SR: 'static, Rs: Hash + Eq + 'static, As: 'static>
|
||||||
resources.insert(storable_resource, future.clone());
|
resources.insert(storable_resource, future.clone());
|
||||||
drop(resources);
|
drop(resources);
|
||||||
trace!(logger, "Resource already added");
|
trace!(logger, "Resource already added");
|
||||||
let (t, did_run) = future.await;
|
Ok(future.await)
|
||||||
Ok((t, did_run))
|
|
||||||
} else {
|
} else {
|
||||||
let inner_weak = Rc::downgrade(&self.0);
|
let inner_weak = Rc::downgrade(&self.0);
|
||||||
let logger_weak = Rc::downgrade(logger);
|
let logger_weak = Rc::downgrade(logger);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue