Skip to content

Commit

Permalink
chore: wrap offset_flush return in pin<box<_>> (#4306)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraidev authored Dec 30, 2024
1 parent f3a3d09 commit 0680e60
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions crates/fluvio/src/consumer/stream.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::pin::Pin;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use std::time::{Duration, SystemTime};
Expand All @@ -12,14 +13,16 @@ use tracing::{info, warn};
use super::config::OffsetManagementStrategy;
use super::{offset::OffsetLocalStore, StreamToServer};

type OffsetFlushFuture<'a> = Pin<Box<dyn Future<Output = Result<(), ErrorCode>> + Send + 'a>>;

/// Extension of [`Stream`] trait with offset management capabilities.
pub trait ConsumerStream: Stream<Item = Result<Record, ErrorCode>> + Unpin {
/// Mark the offset of the last yelded record as committed. Depending on [`OffsetManagementStrategy`]
/// it may require a subsequent `offset_flush()` call to take any effect.
fn offset_commit(&mut self) -> Result<(), ErrorCode>;

/// Send the committed offset to the server. The method waits for the server's acknowledgment before it finishes.
fn offset_flush(&mut self) -> impl Future<Output = Result<(), ErrorCode>> + Send;
fn offset_flush(&mut self) -> OffsetFlushFuture<'_>;
}

pub struct MultiplePartitionConsumerStream<T> {
Expand Down Expand Up @@ -117,7 +120,7 @@ where
self.get_mut().offset_commit()
}

fn offset_flush(&mut self) -> impl Future<Output = Result<(), ErrorCode>> + Send {
fn offset_flush(&mut self) -> OffsetFlushFuture<'_> {
self.get_mut().offset_flush()
}
}
Expand All @@ -129,8 +132,8 @@ impl<T: Stream<Item = Result<Record, ErrorCode>> + Unpin> ConsumerStream
self.offset_mngt.commit()
}

fn offset_flush(&mut self) -> impl Future<Output = Result<(), ErrorCode>> + Send {
self.offset_mngt.flush()
fn offset_flush(&mut self) -> OffsetFlushFuture<'_> {
Box::pin(self.offset_mngt.flush())
}
}

Expand All @@ -144,9 +147,9 @@ impl<T: Stream<Item = Result<Record, ErrorCode>> + Unpin> ConsumerStream
Ok(())
}

fn offset_flush(&mut self) -> impl Future<Output = Result<(), ErrorCode>> + Send {
fn offset_flush(&mut self) -> OffsetFlushFuture<'_> {
let futures: Vec<_> = self.offset_mgnts.iter().map(|p| p.flush()).collect();
try_join_all(futures).map(|r| r.map(|_| ()))
Box::pin(try_join_all(futures).map(|r| r.map(|_| ())))
}
}

Expand Down

0 comments on commit 0680e60

Please sign in to comment.