async-app 0.1.0

Provides ergonomic approach to implement applications spawning event loops
Documentation
  • Coverage
  • 41.67%
    5 out of 12 items documented0 out of 8 items with examples
  • Size
  • Source code size: 25.55 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.71 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • crlf0710/async-app
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • crlf0710

Async application logic entry and event loop spawning

This crate provides ergonomic approach to implement applications spawning event loops. This covers applications using GUI & TUI (Screen rendering and input responding) / Network Services / Audio Services and so on. The main logic is implemented as an async function, and spawning event loops is implemented as Futures that after yielded, returns a proxy object that has access to the event loop. When yielded, the main future is also transfered and continue running on a new thread, leaving the original thread to run the event loop. To avoid pulling unnecessary dependencies, this crate doesn't provide any definitions for event loops, so you usually need to use the definition from another crate, usually with the name async-app-*

The final code will be like:

use async_app_myeventloop::MyEventLoop;
// This macro below expands to some boilerplate to run main future
#[async_app::main]
async fn main(mut scope: async_app::Scope) {
    let proxy = scope
        .fork_and_run_event_loop::<MyEventLoop>()
        .await
        .expect("Failed to spawn event loop");
    // code below runs on the thread #2
    proxy.do_necessary_configuration();
    // thread #1's event loop is now modified with this configuration.
    
    // more application logic here

    // dropping `proxy` here will usually tell the event loop to quit somehow.
}