ralexstokes/ethereum-consensus

refactor `Clock::stream_slots` to use `IntervalStream`

Closed this issue · 6 comments

we can likely use something like this to simplify the clock internals:

https://docs.rs/tokio-stream/latest/tokio_stream/wrappers/struct.IntervalStream.html

fixing this one, github mev bot look away

I'm hitting a roadblock here because tokio::time::interval can only take in non-zero params
As mentioned here: panics

Here's my current Impl:

    pub fn stream_slots(&self) -> impl Stream<Item = Slot> + '_ {
        async_stream::stream! {
            let slot = self.current_slot().expect("after genesis");
            yield slot;
            let mut interval_tick = tokio::time::interval(self.duration_until_slot(slot + 1));
             interval_tick.tick().await;
        }
    }

My bad, I forgot to add the loop:

 pub fn stream_slots(&self) -> impl Stream<Item = Slot> + '_ {
        async_stream::stream! {
            let mut slot = self.current_slot().expect("after genesis");
            let mut interval_tick = tokio::time::interval(self.duration_until_slot(slot + 1));

            loop{
            yield slot;
            interval_tick.tick().await;
            slot = self.current_slot().expect("after genesis");
            }
        }
    }

but now when I run the test_slot_stream it just keeps on going indefinitely:

running 1 test
test clock::tests::test_slot_stream has been running for over 60 seconds

can you open a PR w/ the changes?

the idea behind this issue was to just use IntervalStream, so there is no longer any need to use async_stream::stream!

also, the interval will just be SECONDS_PER_SLOT

you can collect the first tick, yield the current slot, and then just await each tick

Just open a PR w/ the changes

And I couldn't figure out a way to do this :(

the idea behind this issue was to just use IntervalStream, so there is no longer any need to use async_stream::stream!
also, the interval will just be SECONDS_PER_SLOT
you can collect the first tick, yield the current slot, and then just await each tick