Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: LinkRx::recv_async #896

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions rumqttd/src/link/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,23 @@ impl LinkRx {
}
}

pub async fn recv_async(&mut self) -> Result<Option<Notification>, LinkError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is already method named next() which is exactly the same!

// Read from cache first
// One router_rx trigger signifies a bunch of notifications. So we
// should always check cache first
match self.cache.pop_front() {
Some(v) => Ok(Some(v)),
None => {
// If cache is empty, check for router trigger and get fresh notifications
self.router_rx.recv_async().await?;
// Collect 'all' the data in the buffer after a notification.
// Notification means fresh data which isn't previously collected
mem::swap(&mut *self.send_buffer.lock(), &mut self.cache);
Ok(self.cache.pop_front())
}
}
}

pub fn recv_deadline(&mut self, deadline: Instant) -> Result<Option<Notification>, LinkError> {
// Read from cache first
// One router_rx trigger signifies a bunch of notifications. So we
Expand Down
Loading