Skip to content

Use #[tokio::main] instead of hand-rolled Runtime::new().block_on()#788

Open
demoray wants to merge 3 commits into
mainfrom
bcaswell/tokio-main
Open

Use #[tokio::main] instead of hand-rolled Runtime::new().block_on()#788
demoray wants to merge 3 commits into
mainfrom
bcaswell/tokio-main

Conversation

@demoray
Copy link
Copy Markdown
Collaborator

@demoray demoray commented May 18, 2026

Both binaries previously stood up a tokio Runtime by hand, mapped
io::Error to Error::Io, and called .block_on(...). Replace with
#[tokio::main(flavor = "current_thread")], which is the idiomatic
shape and drops the manual error-mapping sites.

  • src/bin/avml-upload.rs: collapse the separate async fn run into
    main. The binary already requires both put and blobstore, so
    no cfg work is needed.
  • src/bin/avml.rs: tokio is feature-gated. Extract the synchronous
    snapshot pipeline into acquire(&Config), then provide two
    cfg-disjoint mains: a sync one when neither upload feature is
    enabled, and a #[tokio::main] async one when either is. The
    blocking snapshot work runs synchronously inside block_on before
    the first .await, matching the existing execution shape.
  • Cargo.toml: add macros to tokio's optional feature set. Without
    it, --features put alone fails to find tokio::main. Other
    feature combinations were transitively pulling it in already.

Verified with:

  • cargo build --no-default-features
  • cargo build --no-default-features --features put
  • cargo build --no-default-features --features blobstore
  • cargo clippy --all-features --all-targets -- -D warnings
  • cargo test --all-features
  • cargo fmt --check

Both binaries previously stood up a tokio `Runtime` by hand, mapped
`io::Error` to `Error::Io`, and called `.block_on(...)`. Replace with
`#[tokio::main(flavor = "current_thread")]`, which is the idiomatic
shape and drops the manual error-mapping sites.

- `src/bin/avml-upload.rs`: collapse the separate `async fn run` into
  `main`. The binary already requires both `put` and `blobstore`, so
  no cfg work is needed.
- `src/bin/avml.rs`: tokio is feature-gated. Extract the synchronous
  snapshot pipeline into `acquire(&Config)`, then provide two
  cfg-disjoint `main`s: a sync one when neither upload feature is
  enabled, and a `#[tokio::main]` async one when either is. The
  blocking snapshot work runs synchronously inside `block_on` before
  the first `.await`, matching the existing execution shape.
- `Cargo.toml`: add `macros` to tokio's optional feature set. Without
  it, `--features put` alone fails to find `tokio::main`. Other
  feature combinations were transitively pulling it in already.

Verified with:

- `cargo build --no-default-features`
- `cargo build --no-default-features --features put`
- `cargo build --no-default-features --features blobstore`
- `cargo clippy --all-features --all-targets -- -D warnings`
- `cargo test --all-features`
- `cargo fmt --check`
@demoray demoray enabled auto-merge (squash) May 18, 2026 17:08
# Conflicts:
#	src/bin/avml-upload.rs
#	src/bin/avml.rs
# Conflicts:
#	src/bin/avml-upload.rs
#	src/bin/avml.rs
@demoray demoray requested a review from cduplantisms May 18, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants