Skip to content

Commit

Permalink
no either type, just return separate stream types
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Sep 5, 2024
1 parent d4eb1bb commit 5d0385a
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions crates/exex/exex/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ use tokio::sync::{
mpsc::{self, error::SendError, Receiver, UnboundedReceiver, UnboundedSender},
watch,
};
use tokio_util::{
either::Either,
sync::{PollSendError, PollSender, ReusableBoxFuture},
};
use tokio_util::sync::{PollSendError, PollSender, ReusableBoxFuture};

/// Metrics for an `ExEx`.
#[derive(Metrics)]
Expand Down Expand Up @@ -143,10 +140,7 @@ impl ExExHandle {
}
}

/// A stream of [`ExExNotification`]s returned by [`ExExNotificationsSubscriber::subscribe`].
pub type ExExNotifications = Either<ExExNotificationsWithoutHead, ExExNotificationsWithHead>;

/// A subscriber for [`ExExNotifications`].
/// A subscriber for a stream of [`ExExNotification`]s.
#[derive(Debug)]
pub struct ExExNotificationsSubscriber {
notifications: Receiver<ExExNotification>,
Expand All @@ -160,24 +154,24 @@ impl ExExNotificationsSubscriber {

/// Subscribe to notifications.
pub fn subscribe(self) -> ExExNotifications {
ExExNotifications::Left(ExExNotificationsWithoutHead(self.notifications))
ExExNotifications(self.notifications)
}

// TODO(alexey): uncomment when backfill is implemented in `ExExNotificationsWithHead`
// /// Subscribe to notifications with the given head.
// ///
// /// Notifications will be sent starting from the head, not inclusive. For example, if
// /// `head.number == 10`, then the first notification will be with `block.number == 11`.
// pub fn subscribe_with_head(head: ExExHead) -> ExExNotifications {
// ExExNotifications::Right(ExExNotificationsWithHead(self.notifications, head))
// pub fn subscribe_with_head(head: ExExHead) -> ExExNotificationsWithHead {
// ExExNotificationsWithHead(self.notifications, head)
// }
}

/// A stream of [`ExExNotification`]s. The stream will emit notifications for all blocks.
#[derive(Debug)]
pub struct ExExNotificationsWithoutHead(Receiver<ExExNotification>);
pub struct ExExNotifications(Receiver<ExExNotification>);

impl Stream for ExExNotificationsWithoutHead {
impl Stream for ExExNotifications {
type Item = ExExNotification;

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Expand Down

0 comments on commit 5d0385a

Please sign in to comment.