Conversation
|
I provided an example of running an event loop on top of tokio. I only use Linux, so I could use help with other native platforms. |
|
If this approach is viable I will work on doc comments. |
|
Preview available at https://egui-pr-preview.github.io/pr/6750-newexternal2 |
|
This looks pretty cool! Just out of curiosity, what are the benefits of running egui in an async way like your example? Versus, just spawning the tokio runtime in another thread. |
Yes exactly. I am building an app with a lot of CRUD. There is plenty of CPU available to run the UI and the async tasks. Not having to worry about anything being |
|
This looks great! Please add the missing doc comments and maybe also mention in the example readme why you'd want to do this (basically what you explained in the comment). |
|
@lucasmerlin I updated the readmes and added doc comments. I fixed the CI issues for windows, ios, mac. I used required-features to prevent building the linux example unless the FWIW, I attempted to extend the async example to windows, but it turns out it's not possible with tokio. It would require changes to mio. To block waiting for GUI events on windows you need to use WaitForMultipleObjectsEx. I tried running it on a background thread, but it only works on the thread that created the window. Hopefully in the future someone who cares more about windows or mac will update the example with async executors that supports waiting for GUI events on their platforms. |
|
@lucasmerlin Sorry the update to 1.84 on master broke CI. Here is a successful CI run with master merged in https://github.com/wpbrown/egui/actions/runs/14708125657 |
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> * Closes emilk#2875 * Closes emilk#3340 * [x] I have followed the instructions in the PR template Adds `create_native`. Similiar to `run_native` but it returns an `EframeWinitApplication` which is a `winit::ApplicationHandler`. This can be run on your own event loop. A helper fn `pump_eframe_app` is provided to pump the event loop and get the control flow state back. I have been using this approach for a few months. --------- Co-authored-by: Will Brown <opensource@rebeagle.com>
eframeto run on an existing event loop #2875Adds
create_native. Similiar torun_nativebut it returns anEframeWinitApplicationwhich is awinit::ApplicationHandler. This can be run on your own event loop. A helper fnpump_eframe_appis provided to pump the event loop and get the control flow state back.I have been using this approach for a few months.