Skip to content

Commit

Permalink
Rename try_recv_buffered() -> next_buffered().
Browse files Browse the repository at this point in the history
  • Loading branch information
chanks committed Oct 13, 2024
1 parent ab1afa2 commit 14a3341
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions sqlx-postgres/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl PgListener {
pub async fn try_recv(&mut self) -> Result<Option<PgNotification>, Error> {
// Flush the buffer first, if anything
// This would only fill up if this listener is used as a connection
if let Some(notification) = self.try_recv_buffered() {
if let Some(notification) = self.next_buffered() {
return Ok(Some(notification));
}

Expand Down Expand Up @@ -300,7 +300,7 @@ impl PgListener {
/// This is similar to `try_recv`, except it will not wait if the connection has not yet received a notification.
///
/// This is helpful if you want to retrieve all buffered notifications and process them in batches.
pub fn try_recv_buffered(&mut self) -> Option<PgNotification> {
pub fn next_buffered(&mut self) -> Option<PgNotification> {
if let Ok(Some(notification)) = self.buffer_rx.try_next() {
Some(PgNotification(notification))
} else {
Expand Down
8 changes: 4 additions & 4 deletions tests/postgres/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ async fn test_listener_try_recv_buffered() -> anyhow::Result<()> {
}

// Check no notification is buffered, since we haven't sent one.
assert!(listener.try_recv_buffered().is_none());
assert!(listener.next_buffered().is_none());

// Send five notifications transactionally, so they all arrive at once.
{
Expand All @@ -1102,7 +1102,7 @@ async fn test_listener_try_recv_buffered() -> anyhow::Result<()> {
}

// Still no notifications buffered, since we haven't awaited the listener yet.
assert!(listener.try_recv_buffered().is_none());
assert!(listener.next_buffered().is_none());

// Activate connection.
sqlx::query!("SELECT 1 AS one")
Expand All @@ -1112,13 +1112,13 @@ async fn test_listener_try_recv_buffered() -> anyhow::Result<()> {
// The next five notifications should now be buffered.
for i in 0..5 {
assert!(
listener.try_recv_buffered().is_some(),
listener.next_buffered().is_some(),
"Notification {i} was not buffered"
);
}

// Should be no more.
assert!(listener.try_recv_buffered().is_none());
assert!(listener.next_buffered().is_none());

// Even if we wait.
assert!(!try_recv(&mut listener).await?, "Notification received");
Expand Down

0 comments on commit 14a3341

Please sign in to comment.