Tokio Interval stops yielding elements inside other Future

I have a custom Stream that also has an Interval as member that is polled when calling poll_next on it. As I understand it the Interval should register the callback function/Waker of the given Context with its underlying timer implementation which should lead to the custom stream being polled at least once every duration, even if the stream returns Poll::Pending every time (because the wakeup is just for internal house keeping). But apparently it doesn't.

I prepared a minimal example. This should print approximately 20 times before finishing but it only does so twice (when I ran it). Does the timeout interfere with it? My real application also heavily relies on timeout to keep peers from stalling during authentication, binding ressources etc., so it's not just used here to make the example bounded in time, it would be nice if it worked that way.

Do I have a fundamental misunderstanding regarding how futures work or could that be a bug?

If the interval returns Poll::Ready(some_item), then it has not scheduled the task for wake-up. Your poll should probably keep calling it in a loop until it returns Poll::Pending.

1 Like

Than you :smiley: that worked.

Turns out I should read the docs more carefully :pensive:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.