Skip to content

Commit

Permalink
Error instead
Browse files Browse the repository at this point in the history
  • Loading branch information
expenses committed Dec 14, 2019
1 parent abf64b7 commit 2f1984a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::fmt;
use std::future::Future;
use std::io;
use std::pin::Pin;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::SeqCst;
Expand Down Expand Up @@ -125,16 +126,19 @@ impl Delay {
}

impl Future for Delay {
type Output = ();
type Output = io::Result<()>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let state = match self.state {
Some(ref state) => state,
None => panic!("timer has gone away"),
None => {
let err = Err(io::Error::new(io::ErrorKind::Other, "timer has gone away"));
return Poll::Ready(err);
}
};

if state.state.load(SeqCst) & 1 != 0 {
return Poll::Ready(());
return Poll::Ready(Ok(()));
}

state.waker.register(&cx.waker());
Expand All @@ -143,8 +147,11 @@ impl Future for Delay {
// state. If we've fired the first bit is set, and if we've been
// invalidated the second bit is set.
match state.state.load(SeqCst) {
n if n & 0b01 != 0 => Poll::Ready(()),
n if n & 0b10 != 0 => panic!("timer has gone away"),
n if n & 0b01 != 0 => Poll::Ready(Ok(())),
n if n & 0b10 != 0 => Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
"timer has gone away",
))),
_ => Poll::Pending,
}
}
Expand Down

0 comments on commit 2f1984a

Please sign in to comment.