-
Notifications
You must be signed in to change notification settings - Fork 634
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
Integrating CurrentThread and foreign event loops #675
Comments
cc @carllerche re: reform branch. |
I'm not sure why this is true as one could impl the Perhaps it would help for me to understand this better if you could explain how this API would be used with glib / gtk? That said, at a high level, something like this seems important. I would just like to have a better sense of how it all fits together. |
Er sorry yeah so what I mean with the glib case is that you have very little control at all. For example Rust as a language integrating into a foreign event loop (like glib) can't block at all (or request to block). It's sort of like if you bolted a tokio-reactor onto a tokio-reactor the sub-reactor wouldn't be able to block, it just knows when it needs to get polled and it can't as the outer reactor to block because that's managed elsewhere. Does that make sense? |
Yeah, roughly. I see why it is needed at a high level. I’m just not exactly sure how the proposed api fits in with something like glib/gtk. I would assume that the argument to poll would take T:Wakeup. What glib fn would that call? Also, in terms of naming bikeshedding (and this is not really related to just this issue), set_default as a name makes it sound like it is a more permanent action and not just for the context of a closure. “with” or “enter” as terms seems more fitting as terms. Anyway, if you want to add this api it seems fine to me. The docs should de-emphasize using it in favor of other options and only reach to this api when necessary for integrating with other loops. |
This commit extracts the `TaskRunner` interface from the `current_thread` module to a standalone interface and also reexports it from the `executor` module. This is done with #675 as the primary motivation, namely accommodating crates using `CurrentThread` on foreign event loops like glib. In this situation Rust (and associated code) can't request to block (aka with `run_with_sleep`) and as a result need a nonblocking method (`TaskRunner::poll` here) instead. The `current_thread` module was then reimplemented in terms of `TaskRunner` to ensure there's no extra duplication.
This commit extracts the `TaskRunner` interface from the `current_thread` module to a standalone interface and also reexports it from the `executor` module. This is done with #675 as the primary motivation, namely accommodating crates using `CurrentThread` on foreign event loops like glib. In this situation Rust (and associated code) can't request to block (aka with `run_with_sleep`) and as a result need a nonblocking method (`TaskRunner::poll` here) instead. The `current_thread` module was then reimplemented in terms of `TaskRunner` to ensure there's no extra duplication.
Going back to the original problem of integrating with a foreign event loop. It seems that code that actually needs to do this is limited to libs that provide bindings for this foreign event loop. This is not to say it is an unimportant case. I wonder if instead of handling all possible current thread executor cases, we instead provide one for the common cases and also provide a way to hook into the This would provide the added benefit of being able to bring your own implementation, optimized for your needs. I don't think doing this would be particularly hard, there would just need to be a way to pass a type UnsyncFuture = Box<Future<Item = (), Error = ()>>;
fn with_my_custom_executor<F, R>(&mut Executor<UnsyncFuture>, f: F) -> R
where F: FnOnce(&mut Executor<UnsyncFuture>) -> R,
{
// ...
} |
Yes I think that would also solve the constraint of allowing integration into foreign event loops while allowing libraries to use |
As I mentioned in #717, I would suggest punting on this issue for the initial "tokio reform" release. |
Agreed; I've untagged. |
I'm going to close this out in favor of the executor RFC |
Today the
CurrentThread
API I think isn’t easily amenable to integration with a foreign event loop, such as the glib event loop in GTK. (a case I've forgotten about until now by accident!). The main gist of the problem is that right now the main way to customize theCurrentThread
behavior is via theSleep
trait but that requires that Rust is the one which requests that the current thread block, whereas in a GTK/glib application Rust isn't the one doing that but C is.I think we may want to add some form of nonblocking "move spawned tasks forward" API like:
With an API like that we could update the existing APIs behaviorally like:
Effectively we'd just export some of the internals of the current thread module to interact a little more closely with external systems. We'd then require foreign event loop integration to look like:
TaskRunner
set_default
to get spawning to workTaskRunner
is polled with the ability to route wakeups to the glib event loopI think this'd work for glib integration, but curious what others think!
The text was updated successfully, but these errors were encountered: