-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Asynchronous Seek and Seek implementation for File #785
Conversation
That was a fast turnaround from issue to PR! 👍 I'll try and take a look at this today. WRT your
We definitely can't delete them yet, for obvious backwards-compatibility reasons, but we should definitely push people towards the better path if possible. |
I was mostly confused about a |
Yeah, I'd say let's add the above, and set |
I have deprecated the |
Actually, now that I've gone and looked at it.... I say we should make the version be 0.1.5 will be when we release this, and 0.2 will be when we delete the deprecated methods. Sorry about the back and forth! |
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.
Left a few minimal nits, but had some thoughts overall....
So, AsyncRead
inherits Read
, and AsyncWrite
inherits Write
, but this is something that will change in the future with a breaking release. It was a mistake to inherit them, and ideally, we want async-only types to only implement asynchronous public methods.
Given that impl Seek for File
only works when run via an executor, it feels like we should drop that impl, and only implement AsyncSeek
for File
.
The tricky part is that we still want the behavior of ::would_block
because the threadpool may actually run out of blocking threads to spawn on to, so we have to account for that.
I'm happy to give it a go, but I'm a little bit confused about what the future breaking release would look like. Right now it looks like you need to implement I don't think there is any similar infrastructure for |
Sorry, mostly that in the pre-1.0 world, we've been treating minor releases as our way to distinguish breaking updates. Since we're in 0.1 now, we would do this new method/deprecate old stuff as a patch version, then eventually drop the deprecated methods in a minor, breaking version release. The deprecation cleanup isn't anything you have to be concerned with, but just wanted to clarify.
In general, letting people ever call There's a good chunk of infrastructure that |
Ok, I think I've made the required changes. A summary:
I removed the implementations for (An aside: should I try to form a similar PR for the futures crate?) |
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.
I think this is good to merge.
Thanks again, and sorry for the long lead time on getting it merged. 👍
@tobz restarted a failed travis job, CI looks green now, but I'll let you merge |
@tobz is this still good to merge? might need it soon |
Is this PR ready? Similarly in need of this feature. |
This patch contains a special hack that circumvents the current tokio seek problem. tokio `seek` is implemented to take ownership of the original File and emit a new one in its future, which conflicts with the design of ResourceTable. To avoid the problem, the current hack makes the FsFile resource an Option which we could `take` the value ownership out of it. We then convert the tokio File into a Rust std File, perform the seek, and then put it back into the resource. This might be able to drop this hack after tokio-rs/tokio#785 lands.
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.
Question inline
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.
Posting the Request changes
review until the question re: poll_seek
name conflict is resolved.
This patch contains a special hack that circumvents the current tokio seek problem. tokio `seek` is implemented to take ownership of the original File and emit a new one in its future, which conflicts with the design of ResourceTable. To avoid the problem, the current hack makes the FsFile resource an Option which we could `take` the value ownership out of it. We then convert the tokio File into a Rust std File, perform the seek, and then put it back into the resource. This might be able to drop this hack after tokio-rs/tokio#785 lands.
@carllerche I've added a test for Any suggestions, or is this good? |
@agrif Ok... I think we can make this work out. The deprecated annotation should be removed. Unfortunately, because the compiler defaults to the inherent method (on Besides that, there is a bunch of other smaller tweaks I would do, but I can try to tackle it myself on monday or tuesday if you don't want to (it's a bit hard to explain). A lot of the Basically:
|
Ok, I've removed the deprecation annotation on |
Just wanted to ping this to check the status. @carllerche, based on the last comment it looks like @agrif is expecting input from you. |
@agrif, Can this PR also implement My use case is I want to be able to use the seek method on a csv Reader build on top of a |
@EliSnow the original version of this pull request had It would be easy enough to add a |
Adding |
So the concern @carllerche had with Suppose someone polls a seek operation, maybe several times in succession, and it always returns We considered three different behaviors/guarantees of asynchronous seek:
In the end, we chose the 3rd option because that behavior feels most natural and consistent with the way This PR looks good to me and doesn't seem to affect our choice of guarantees around seeking. |
Unfortunately it looks like there are merge conflicts, but the PR can be merged once those are resolved. Thanks. |
These have been replaced by io::AsyncSeek and io::Seek<File>.
I've rebased on to the latest master. Along the way, I updated the deprecation annotations to point to |
Just poking you folks for an update. It's been 235 days since this PR was opened, and I no longer even remember what I was trying to do when I ran into this limitation. Is there something I can do to help this along? |
This patch contains a special hack that circumvents the current tokio seek problem. tokio `seek` is implemented to take ownership of the original File and emit a new one in its future, which conflicts with the design of ResourceTable. To avoid the problem, the current hack makes the FsFile resource an Option which we could `take` the value ownership out of it. We then convert the tokio File into a Rust std File, perform the seek, and then put it back into the resource. This might be able to drop this hack after tokio-rs/tokio#785 lands.
Follow up here: #1641 |
(Original issue: #776)
Motivation
AsyncRead
andAsyncWrite
provide a way to do asynchronous I/O without caring about the specific underlying implementation. No such interface exists for seeking, though.Solution
I implemented
AsyncSeek
, modeled afterAsyncRead
andAsyncWrite
. Like those, it comes with a default implementation that relies on the underlyingSeek
implementation to useWouldBlock
errors.I also added
tokio_io::io::seek
, a future-flavored seek call built on top ofAsyncSeek
. The future it returns is almost an exact copy ofSeekFuture
fromtokio_fs
, but I kept both structs around since one has a type argument and one does not.Finally, I implemented
AsyncSeek
onFile
, and changed the existing test to use the newio::seek
. The methodsseek
andpoll_seek
onFile
(as well asSeekFuture
) should probably be deprecated, but I'm not sure how that works.