mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-27 00:00:12 +02:00
util: fuse PollSemaphore (#3578)
This commit is contained in:
@@ -55,12 +55,13 @@ impl PollSemaphore {
|
||||
/// the `Waker` from the `Context` passed to the most recent call is
|
||||
/// scheduled to receive a wakeup.
|
||||
pub fn poll_acquire(&mut self, cx: &mut Context<'_>) -> Poll<Option<OwnedSemaphorePermit>> {
|
||||
match ready!(self.permit_fut.poll(cx)) {
|
||||
Ok(permit) => {
|
||||
let next_fut = Arc::clone(&self.semaphore).acquire_owned();
|
||||
self.permit_fut.set(next_fut);
|
||||
Poll::Ready(Some(permit))
|
||||
}
|
||||
let result = ready!(self.permit_fut.poll(cx));
|
||||
|
||||
let next_fut = Arc::clone(&self.semaphore).acquire_owned();
|
||||
self.permit_fut.set(next_fut);
|
||||
|
||||
match result {
|
||||
Ok(permit) => Poll::Ready(Some(permit)),
|
||||
Err(_closed) => Poll::Ready(None),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user