gj icon indicating copy to clipboard operation
gj copied to clipboard

Asynchronous file I/O

Open dermesser opened this issue 8 years ago • 5 comments

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?

dermesser avatar Apr 19 '16 05:04 dermesser

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.

dwrensha avatar Apr 19 '16 11:04 dwrensha

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.

burdges avatar Apr 19 '16 13:04 burdges

@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 :-)

dermesser avatar Apr 19 '16 14:04 dermesser

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.

dwrensha avatar Apr 19 '16 14:04 dwrensha

...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.

dermesser avatar Apr 25 '16 19:04 dermesser