-
Notifications
You must be signed in to change notification settings - Fork 339
Add future::timeout() #20
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
Conversation
Can we somehow mark interfaces as experimental? |
Sounds good! Maybe with a config flag to avoid them? |
You mean feature flag? |
Ah, right - yes, a feature flag. |
I feel reluctant to put stuff behind feature flags at this point since we're releasing a preview version with plenty of time till 1.0 release, and can do breaking changes before then. Wdyt? |
You are right, if we are reasonably sure, we can do it this way. |
type Output = Result<F::Output, TimeoutError>; | ||
|
||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
match self.as_mut().future().poll(cx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean that in case of a CPU-bound future that is blocking the current thread you will never try to poll the timer and return TimeoutError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @stjepang
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kpp That's a good point - do you think we should check for timeout before polling the future?
I worry a bit that this would add overhead to futures that are quick to poll or immediately ready. And if the future is CPU-bound and takes a really long time, we can still get stuck if the timeout occurs while that future is running.
All things considered, I think I prefer the current behavior. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All things considered, I think I prefer the current behavior.
Yep... I don't see a better solution for this.
Still I would rewrite the current implementation as f.select(Delay::new(dur))...
;)
Also notice how this code can be reduced: #113 |
BTW what's the difference between future::timeout() and io::timeout()? |
@kpp |
Co-Authored-By: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
Co-Authored-By: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
I put this function behind the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! -- not sure we need the unstable
feature here, but not opposed to being cautious either (: -- let's go ahead and merge!!
cc #18