Skip to content
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

Add support for asynchronous code #25

Merged
merged 1 commit into from
May 7, 2023
Merged

Add support for asynchronous code #25

merged 1 commit into from
May 7, 2023

Conversation

CryZe
Copy link
Collaborator

@CryZe CryZe commented May 7, 2023

This allows you to define an asynchronous main function instead of the poll based update function, which allows you to more easily keep state between individual ticks of the runtime. Unfortunately the most efficient implementation isn't possible yet on stable Rust, as we are blocked by the following two features:

For now we have to use a workaround that is less efficient by calling the main function at runtime and allocating it onto a new WebAssembly page.

Here is a full example of how an auto splitter could look like using the async_main macro:

Usage on stable Rust:

async_main!(stable);

Usage on nightly Rust:

async_main!(nightly);

The asynchronous main function itself:

async fn main() {
    // TODO: Set up some general state and settings.
    loop {
        let process = Process::wait_attach("explorer.exe").await;
        process.until_closes(async {
            // TODO: Load some initial information from the process.
            loop {
                // TODO: Do something on every tick.
               next_tick().await;
            }
        }).await;
    }
}

@CryZe CryZe added the enhancement New feature or request label May 7, 2023
This allows you to define an asynchronous `main` function instead of the
poll based `update` function, which allows you to more easily keep state
between individual ticks of the runtime. Unfortunately the most
efficient implementation isn't possible yet on stable Rust, as we are
blocked by the following two features:
- [type_alias_impl_trait](rust-lang/rust#63063)
- [const_async_blocks](rust-lang/rust#85368)

For now we have to use a workaround that is less efficient by calling
the `main` function at runtime and allocating it onto a new WebAssembly
page.

Here is a full example of how an auto splitter could look like using the
`async_main` macro:

Usage on stable Rust:
```rust
async_main!(stable);
```

Usage on nightly Rust:
```rust

async_main!(nightly);
```

The asynchronous main function itself:
```rust
async fn main() {
    // TODO: Set up some general state and settings.
    loop {
        let process = Process::wait_attach("explorer.exe").await;
        process.until_closes(async {
            // TODO: Load some initial information from the process.
            loop {
                // TODO: Do something on every tick.
               next_tick().await;
            }
        }).await;
    }
}
```
@CryZe CryZe merged commit 7afafed into master May 7, 2023
@CryZe CryZe deleted the futures branch May 7, 2023 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant