-
Notifications
You must be signed in to change notification settings - Fork 54
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
fix: Run our own async executor on Unix #337
Conversation
ca4c53a
to
d558681
Compare
d558681
to
5bec14c
Compare
With this change (unlike the current
Spawning zbus futures on a non-tokio executor fails if the I raised this issue on zbus earlier in dbus2/zbus#526. I'm not sure exactly what is the best way for zbus or accesskit to avoid this, but it definitely doesn't seem ideal. |
@ids1024 Yes we all know the situation isn't ideal here. Of course if you already depend on tokio then you are supposed to activate accesskit_unix's tokio feature (or the accesskit_winit). I think I will add a note about this in the README. |
We could have also unconditionally used async-io executor even if tokio is used at the application level, but then we force all these async-io dependencies on tokio users. At the moment I decided not to do that and make sure to exclude as much of these crates as possible when the tokio feature is enabled. |
Maybe I should note that the only reason it doesn't crash currently is because we fallback to |
Do we still need to use |
Just to be safe, can we also issue a compile error if both the async-io and tokio features are set? And is there any way we can check at compile time whether the feature selection for zbus matches the one for our own crate? |
I missed that, good catch!
Unfortunately this is not possible as Cargo doesn't pass dependency features to the crate being compiled. The assumption here is if someone enables the |
@DataTriny Good work. Are you waiting for anyone else to review this? If not, feel free to merge. |
I'll just mention that the Unix adapter runs perfectly fine with the default feature inside a tokio-based program, just like zbus. I'm happy to revisit this if someone comes with a better approach. |
Is there a way to make this customizable? We're trying to keep the threading story for Bevy consistent, and extra threads pose potential performance issues due to the engine's sensitivity to context switches. Requiring async-std or tokio are also both not feasible given our constraints. |
@james7132 We have no choice but to depend transitively on async-io or tokio as long as we use zbus. And if we move away from zbus, someone will dislike that we're either using a C library (e.g. via the dbus crate) or fragmenting the ecosystem (by forking zbus). Apparently we can't please everyone at once. This is why we agreed to the compromise of feature-gating the AccessKit Unix adapter in We also have no choice but to start a thread for the D-Bus connection, because winit doesn't give us a way to add our file descriptor(s) to its event loop. |
Fixes #332
Depends on #336
Unix adapters can now be used inside both a sync and an async context. All D-Bus communications now happen on another thread, which runs its own async executor. The internal executor of zbus connections are disabled and replaced by tasks which run on the same thread. Abstraction helpers have been copied from zbus to be as much runtime agnostic as possible.
This PR can be tested by modifying the accesskit_winit simple example:
#[async_std::main]
or#[tokio::main]
,