use crate::pipeline::apply::event::{ApplyEvent, PositionedEvent};
use anyhow::Result;
use surreal_sync_core::Change;
#[derive(Debug, Clone)]
pub struct PositionedChange<P> {
pub change: Change,
pub position: P,
}
impl<P> PositionedChange<P> {
pub fn new(change: Change, position: P) -> Self {
Self { change, position }
}
pub fn into_event(self) -> PositionedEvent<P> {
PositionedEvent::new(ApplyEvent::Change(self.change), self.position)
}
}
impl<P> From<PositionedChange<P>> for PositionedEvent<P> {
fn from(pc: PositionedChange<P>) -> Self {
pc.into_event()
}
}
#[async_trait::async_trait]
pub trait ChangeFeed: Send {
type Position: Clone + Send + Sync + 'static;
async fn poll_changes(&mut self) -> Result<Vec<PositionedChange<Self::Position>>>;
async fn advance_watermark(&mut self, position: Self::Position) -> Result<()>;
fn is_finished(&self) -> bool {
false
}
}