Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor Clock::stream_slots to use IntervalStream #215

Closed
ralexstokes opened this issue Aug 16, 2023 · 6 comments · Fixed by #385
Closed

refactor Clock::stream_slots to use IntervalStream #215

ralexstokes opened this issue Aug 16, 2023 · 6 comments · Fixed by #385
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ralexstokes
Copy link
Owner

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

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

@ralexstokes ralexstokes added enhancement New feature or request good first issue Good for newcomers labels Aug 16, 2023
@Perelyn-sama
Copy link

fixing this one, github mev bot look away

@Perelyn-sama
Copy link

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;
        }
    }

@Perelyn-sama
Copy link

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

@ralexstokes
Copy link
Owner Author

can you open a PR w/ the changes?

@ralexstokes
Copy link
Owner Author

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

@Perelyn-sama
Copy link

Perelyn-sama commented Oct 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
2 participants