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

Make tokio unstable opt in #73

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ sim.client("client", async move {
sim.run();
```

`RUSTFLAG="--cfg tokio_unstable"` is necessary to compile the project.

See `ping_pong` in [udp.rs](tests/udp.rs) for a networking example. For more
examples, check out the [tests](tests) directory.

### tokio_unstable

Turmoil uses [unhandled_panic] to forward host panics as test failures. See
[unstable features] to opt in.

[unhandled_panic]: https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html#method.unhandled_panic
[unstable features]: https://docs.rs/tokio/latest/tokio/#unstable-features

## License

This project is licensed under the [MIT license](LICENSE).
Expand Down
15 changes: 9 additions & 6 deletions src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ impl Rt {
}

fn init() -> (Runtime, LocalSet) {
let tokio = tokio::runtime::Builder::new_current_thread()
.enable_time()
.start_paused(true)
.unhandled_panic(tokio::runtime::UnhandledPanic::ShutdownRuntime)
.build()
.unwrap();
let mut builder = tokio::runtime::Builder::new_current_thread();

#[cfg(tokio_unstable)]
builder.unhandled_panic(tokio::runtime::UnhandledPanic::ShutdownRuntime);

let tokio = builder.enable_time().start_paused(true).build().unwrap();

tokio.block_on(async {
// Sleep to "round" `Instant::now()` to the closest `ms`
Expand All @@ -100,6 +100,9 @@ fn init() -> (Runtime, LocalSet) {

fn new_local() -> LocalSet {
let mut local = LocalSet::new();

#[cfg(tokio_unstable)]
local.unhandled_panic(tokio::runtime::UnhandledPanic::ShutdownRuntime);

local
}