gj
gj copied to clipboard
Asynchronous file I/O
Right now it seems that you can only do blocking I/O from and to files; this also restricts some use cases of capnp-rpc-rust. Right now it seems that mio doesn't support files itself -- so I guess that makes it harder, if not impossible? Or would there be some shortcut?
My plan here is to provide integration with a thread pool, so that you can easily farm out disk I/O and cpu-intensive computation to separate threads, where they will not hold up the main event loop.
There is not even an issue for this at mio
either, so presumably they do not plan on supporting it. There is probably a good reason for that, which could be documented somewhere around the mio
project.
@dwrensha I thought more or less the same, but I've been having difficulties with the lifetimes and Sendability of file references and sockets. Have you already worked with that and could provide an example (e.g. by putting something into the thread example)?
By the way, I'm just asking these questions because GJ is pretty awesome aside from that issue, and I want to be able to use it more :-)
In the design I have in mind, the thread pool would be used through a method that looks like this:
impl ThreadPool {
fn execute<F, T>(&mut self, job: F) -> Promise<T, ::std::io::Error>
where F: FnOnce() -> T,
F: Send + 'static,
T: Send + 'static,
{
//....
}
}
Since gjio
socket types are not Send
, you would still need to do your network I/O on the main eventloop thread.
...I suppose the Send + 'static
restriction is the main problem (at least it was when playing around with it). Not one that's solved easily, though.