Skip to content

Commit

Permalink
fix(hydroflow_plus): add missing sample_every for singletons (#1461)
Browse files Browse the repository at this point in the history
Discovered during a live-coding demo, we only had it for optionals
before.
  • Loading branch information
shadaj authored Sep 23, 2024
1 parent afe78c3 commit d4320e3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions hydroflow_plus/src/singleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,27 @@ impl<'a, T, B, N: Location> Singleton<'a, T, B, NoTick, N> {
HfPlusNode::Unpersist(Box::new(self.ir_node.into_inner())),
)
}

pub fn sample_every(
self,
duration: impl Quoted<'a, std::time::Duration> + Copy + 'a,
) -> Stream<'a, T, Unbounded, NoTick, N> {
let interval = duration.splice_typed();

let samples = Stream::<'a, (), Bounded, Tick, N>::new(
self.location_kind,
self.ir_leaves.clone(),
HfPlusNode::Source {
source: HfPlusSource::Interval(interval.into()),
location_kind: self.location_kind,
},
);

self.latest_tick()
.continue_if(samples.first())
.latest()
.tick_samples()
}
}

impl<'a, T, N: Location> Singleton<'a, T, Unbounded, NoTick, N> {
Expand Down

0 comments on commit d4320e3

Please sign in to comment.