capnproto / capnproto-rust

Cap'n Proto for Rust
MIT License
2.08k stars 222 forks source link

Invoking closure on the event loop to get a mutable reference to self #450

Open ranfdev opened 1 year ago

ranfdev commented 1 year ago

Capnproto interfaces are translated to traits with methods taking &mut self. So, from my understanding, there's an event loop taking the ownership of self, which receives RPC calls and then executes the correct methods.

Can we add a way to schedule a closure on that event loop, to get access to &mut self?

Something like this:

self.dispatch(|this: &mut Self| async {});
dwrensha commented 1 year ago

This is somewhat similar to https://github.com/capnproto/capnproto-rust/issues/87, which is about calling RPC methods on self. Off the top of my head, I'm not sure how to make all the types and traits work out, but it does seem like it should be possible.