diff --git a/src/reactor.rs b/src/reactor.rs index 32a2a11..6b933ba 100644 --- a/src/reactor.rs +++ b/src/reactor.rs @@ -476,7 +476,7 @@ impl Source { dir, ticks: None, index: None, - _guard: None, + _capture: PhantomData, } } } @@ -566,7 +566,7 @@ struct Ready>, T> { dir: usize, ticks: Option<(usize, usize)>, index: Option, - _guard: Option>, + _capture: PhantomData T>, } impl>, T> Unpin for Ready {} @@ -580,7 +580,6 @@ impl> + Clone, T> Future for Ready { dir, ticks, index, - _guard, .. } = &mut *self; @@ -602,12 +601,6 @@ impl> + Clone, T> Future for Ready { Some(i) => i, None => { let i = state[*dir].wakers.insert(None); - *_guard = Some(RemoveOnDrop { - handle: handle.clone(), - dir: *dir, - key: i, - _marker: PhantomData, - }); *index = Some(i); *ticks = Some((Reactor::get().ticker(), state[*dir].tick)); i @@ -631,20 +624,15 @@ impl> + Clone, T> Future for Ready { } } -/// Remove waker when dropped. -struct RemoveOnDrop>, T> { - handle: H, - dir: usize, - key: usize, - _marker: PhantomData T>, -} - -impl>, T> Drop for RemoveOnDrop { +impl>, T> Drop for Ready { fn drop(&mut self) { - let mut state = self.handle.borrow().source.state.lock().unwrap(); - let wakers = &mut state[self.dir].wakers; - if wakers.contains(self.key) { - wakers.remove(self.key); + // Remove our waker when dropped. + if let Some(key) = self.index { + let mut state = self.handle.borrow().source.state.lock().unwrap(); + let wakers = &mut state[self.dir].wakers; + if wakers.contains(key) { + wakers.remove(key); + } } } }