feat(engine): refactor funnel to allow skipping of events

This commit is contained in:
Federico Terzi 2021-10-13 22:35:02 +02:00
parent 379ab08cf1
commit 0b23a5cc30
3 changed files with 10 additions and 3 deletions

View File

@ -48,7 +48,10 @@ impl<'a> Funnel for DefaultFunnel<'a> {
.expect("invalid source index returned by select operation"); .expect("invalid source index returned by select operation");
// Receive (and convert) the event // Receive (and convert) the event
let event = source.receive(op); if let Some(event) = source.receive(op) {
FunnelResult::Event(event) FunnelResult::Event(event)
} else {
FunnelResult::Skipped
}
} }
} }

View File

@ -27,7 +27,7 @@ mod default;
pub trait Source<'a> { pub trait Source<'a> {
fn register(&'a self, select: &mut Select<'a>) -> usize; fn register(&'a self, select: &mut Select<'a>) -> usize;
fn receive(&'a self, op: SelectedOperation) -> Event; fn receive(&'a self, op: SelectedOperation) -> Option<Event>;
} }
pub trait Funnel { pub trait Funnel {
@ -36,6 +36,7 @@ pub trait Funnel {
pub enum FunnelResult { pub enum FunnelResult {
Event(Event), Event(Event),
Skipped,
EndOfStream, EndOfStream,
} }

View File

@ -68,6 +68,9 @@ impl<'a> Engine<'a> {
debug!("end of stream received"); debug!("end of stream received");
return ExitMode::Exit; return ExitMode::Exit;
} }
FunnelResult::Skipped => {
// This event has been skipped, no need to handle it
}
} }
} }
} }