Skip to content

Commit c8a31e3

Browse files
asonixspacejam
authored andcommitted
Follow @rrichardson's lead and only poll oneshots in one place
1 parent 7fdd900 commit c8a31e3

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

src/subscriber.rs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,6 @@ impl Subscriber {
133133
};
134134
}
135135
}
136-
137-
fn poll_oneshot(
138-
self: &mut Pin<&mut Self>,
139-
mut oneshot: OneShot<Option<Event>>,
140-
cx: &mut Context<'_>,
141-
) -> Option<Poll<Option<Event>>> {
142-
match Future::poll(Pin::new(&mut oneshot), cx) {
143-
Poll::Ready(Some(event)) => Some(Poll::Ready(event)),
144-
Poll::Ready(None) => None,
145-
Poll::Pending => {
146-
self.existing = Some(oneshot);
147-
Some(Poll::Pending)
148-
}
149-
}
150-
}
151136
}
152137

153138
impl Future for Subscriber {
@@ -158,20 +143,25 @@ impl Future for Subscriber {
158143
cx: &mut Context<'_>,
159144
) -> Poll<Self::Output> {
160145
loop {
161-
if let Some(future_rx) = self.existing.take() {
162-
if let Some(poll) = self.poll_oneshot(future_rx, cx) {
163-
return poll;
164-
}
165-
}
166-
167-
match self.rx.try_recv() {
168-
Ok(future_rx) => {
169-
if let Some(poll) = self.poll_oneshot(future_rx, cx) {
170-
return poll;
146+
let mut future_rx = if let Some(future_rx) = self.existing.take() {
147+
future_rx
148+
} else {
149+
match self.rx.try_recv() {
150+
Ok(future_rx) => future_rx,
151+
Err(TryRecvError::Empty) => break,
152+
Err(TryRecvError::Disconnected) => {
153+
return Poll::Ready(None)
171154
}
172155
}
173-
Err(TryRecvError::Empty) => break,
174-
Err(TryRecvError::Disconnected) => return Poll::Ready(None),
156+
};
157+
158+
match Future::poll(Pin::new(&mut future_rx), cx) {
159+
Poll::Ready(Some(event)) => return Poll::Ready(event),
160+
Poll::Ready(None) => continue,
161+
Poll::Pending => {
162+
self.existing = Some(future_rx);
163+
return Poll::Pending;
164+
}
175165
}
176166
}
177167
let mut home = self.home.write();

0 commit comments

Comments
 (0)