-
Notifications
You must be signed in to change notification settings - Fork 63
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
add a read_events_with_timeout() #106
Comments
Thank you for the suggestion, @ceyusa. I think another workaround would be to use I'm not opposed to adding the suggested |
That makes more sense in Rust. Thanks! Do you know if that works nowadays? if it does, I think the issue should be closed. |
I haven't tried it, but I have no reason to believe that it won't work. I'd be interested to hear back, if you try it. |
I kind of did it. Though it doesn't look clean to me (perhaps because I'm not used to these idioms): I spawn a thread with this loop:
The funny thing is that I wonder if there's a way to avoid this nesting. |
Unfortunately, I know very little about Tokio myself, so all I'm writing here might be wrong. Are you sure that the call to |
The problem is that deadline is a Tokio's timer, and its documentation mentions:
In order to use FutureExt::deadline it is required to use a Runtime. |
I understand. I hope there's some better way to do this, but I don't know of one. If anyone submitted a pull request implementing the proposed |
Let me continue sharing my experiences on this issue. Just found out that I could do what a want (a cheap thread pushing for events) using tokio as loop event, without the deadline.
And it works great with inotify 0.5. I decide to make a new example using tokio's runtime, but in release 0.6 there's the commit b1b07af which I don't fully understand. Besides, I cannot find a way to add a static mutable buffer in the future stream for tokio's runtime:
I got this:
I wonder how I can set in the future stream a static mutable vector for the event loop. |
@ceyusa Thank you for your feedback, and thanks for the pull request. I don't have time to look into it right now, but I'll get back to you as soon as I can! |
I made this change for two reasons. First, to bring the API closer to the underlying inotify API (which works on a buffer provided by the user), but mostly, to give the user the choice on how big to make that buffer. Previously, the size was hardcoded. I didn't realize that this would be causing problems with the Tokio API.
I see you found a way to do it now. It's really bad that something like this is required. I've opened #120. |
Moin Hanno, issue-120-workaround.rs doesn't show how to apply a timeout. Though I lived there, I'm no tokio specialist, so not sure where to add it. But worse, it uses So I would very much like to have a low level function as initially requested using (not If you don't have time, I could try to add it. |
Hi Daniel, I think you're referring to an example that was added back in 2018 and is no longer in this repository. This issue is also from 2018, which was like 4 breaking releases ago. I don't know how much that example, or anything discussed here, reflect the current API. I also don't know what the state of the art is regarding async and timeouts, and if whatever that is should be used with inotify, or if we need our own method for the non-async API. My concern about duplication between the async and non-async APIs remains. I don't have the expertise to provide much guidance, and have doubts about expanding the non-async API for use cases that would possibly be better served by the async one. For that reason, it would fall on you as the contributor to figure out what's right, then make your case to convince me. I certainly don't intend to be difficult. It it turns out it makes sense to expand the non-async API, that's what we'll do. But my favorite solution would definitely be to know for certain that such a non-async function is not needed. |
My problem is actually the following: I collect data and email it at midnight or shutdown. The latter is tricky. In a signal handler I'm not allowed to do much and Otherwise it doesn't really matter, whether I get a timeout, or sleep and |
How about this:
Do you think something like this would work for your case? |
It seems kinda crazy, to turn a "simpe" CLI into async all over the place… OTOH this sounds like it might work, so thanks for the detailed steps! |
I don't know, I think once you do signal handling, your CLI isn't that simple anymore 😄 Plus, it sounds like your use of async can be restricted to the one function that handles inotify events, so "all over the place" isn't the right characterization here, I think. |
That would imply to use a select on the inotify's fd waiting for data in the fd or the timeout.
The workaround would be to use the nix crate with Inotify's RawFD and do the select in the application.
The text was updated successfully, but these errors were encountered: