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

Change Signal::delay to use ring_buffer::Fixed? #84

Open
mitchmindtree opened this issue Nov 13, 2017 · 1 comment
Open

Change Signal::delay to use ring_buffer::Fixed? #84

mitchmindtree opened this issue Nov 13, 2017 · 1 comment

Comments

@mitchmindtree
Copy link
Member

mitchmindtree commented Nov 13, 2017

Currently Signal::delay simply uses a frame countdown to delay yielding frames from the inner signal. Only once the countdown reaches 0 does it begin requesting frames from the delayed signal.

One potential issue with this is that next is not called on the inner signal until the delay countdown is complete. This can be a problem if the inner signal has some kind of side-effect, e.g. if it monitors the signal in some way and sends values to another thread, a large delay will cause monitoring to hault for the duration of the delay.

This could be fixed by using a fixed-length ring buffer. In this case, a frame could be requested from the inner signal every time next is called (rather than just after the delay is finished) and instead of yielding them immediately they are pushed to the back of the ring buffer and the frame at the front of the ring buffer is returned instead. This way the output would have the same behaviour as the current delay, but it would ensure that next is called on the inner signal every frame.

An alternative approach might be to offer both? The current implementation is much more memory efficient, especially in the case of long delays, and so would surely be preferable in some cases. I can see a couple of options for this:

  1. Provide two methods. E.g. change delay to use a ring buffer, and move the current implementation to a lazy_delay method?
  2. Make Delay generic over usize (a number of frames) and ring_buffer::Fixed (buffered delay).
@linclelinkpart5
Copy link
Contributor

My vote would be for option 1, it makes the most sense intuitively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants