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

stream: add StreamExt::timeout() #2149

Merged
merged 4 commits into from
Jan 24, 2020
Merged

Conversation

alce
Copy link
Member

@alce alce commented Jan 21, 2020

Adds a per-item timeout to Stream

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alce a couple of notes:

  1. it looks like the feature flagging of the timeout method to depend on the "time" feature isn't complete?
  2. looks like the basic_usage test has failed on MacOS but passed on Linux...I wonder if, rather than there being an OS-related failure, the test is flaky/non-deterministic?

tokio/src/stream/mod.rs Show resolved Hide resolved
tokio/src/stream/mod.rs Outdated Show resolved Hide resolved
@alce
Copy link
Member Author

alce commented Jan 22, 2020

Thank you @hawkw. I fixed the flaky test and feature-gated as suggested.

@alce
Copy link
Member Author

alce commented Jan 23, 2020

There are 2 things I didn't think of when implementing this that may make sense:

  • reuse the Timeout struct that is already in the time module and implement Stream on that instead of introducing a new struct

  • keep an additional global timer or counter to stop polling if the inner stream gets stuck for too long on an individual item. If this makes sense it would probably be necessary to introduce a different error, maybe ItemElapsed?

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 👍 I had a behavior question I wrote up inline.

tokio/src/stream/mod.rs Outdated Show resolved Hide resolved
tokio/src/stream/timeout.rs Outdated Show resolved Hide resolved
tokio/src/stream/timeout.rs Outdated Show resolved Hide resolved
tokio/src/stream/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍 thanks for sticking w/ this.

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, modulo one docs nit!

tokio/src/stream/mod.rs Outdated Show resolved Hide resolved
@alce alce requested a review from carllerche January 24, 2020 23:21
@carllerche carllerche merged commit 12be90e into tokio-rs:master Jan 24, 2020
@alce alce deleted the stream-timeout branch January 24, 2020 23:26
@taiki-e taiki-e mentioned this pull request Oct 5, 2020
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

Successfully merging this pull request may close these issues.

None yet

3 participants