-
Notifications
You must be signed in to change notification settings - Fork 280
Open
Description
Hello everyone! I noticed that the ConnectionError::RequestsDone
error in rumqttc can be used to implement graceful program shutdown, but during actual runtime, after AsyncClient
exits, the EventLoop
still holds request_tx
, preventing this error from being caught. Moreover, the request_tx
held by EventLoop
doesn't seem to serve any purpose within the EventLoop
itself. Could it be removed to ensure that only AsyncClient holds request_tx
?
In the EventLoop::next_request
method, when all senders are dropped, it returns a ConnectionError::RequestsDone
error
async fn next_request(
pending: &mut VecDeque<Request>,
rx: &Receiver<Request>,
pending_throttle: Duration,
) -> Result<Request, ConnectionError> {
if !pending.is_empty() {
time::sleep(pending_throttle).await;
// We must call .next() AFTER sleep() otherwise .next() would
// advance the iterator but the future might be canceled before return
Ok(pending.pop_front().unwrap())
} else {
match rx.recv_async().await {
Ok(r) => Ok(r),
Err(_) => Err(ConnectionError::RequestsDone),
}
}
}
If this issue is accepted, I'd be happy to submit a PR on this issue. 😊
Metadata
Metadata
Assignees
Labels
No labels