Skip to content

Commit

Permalink
Merge pull request #444 from stlankes/tokio
Browse files Browse the repository at this point in the history
add tokio example
  • Loading branch information
mkroening authored Jul 31, 2023
2 parents aadcc7a + 83d3796 commit 89053d1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"benches/alloc",
"benches/netbench",
"benches/micro",
"examples/tokio",
"examples/hello_world",
"examples/httpd",
"examples/demo",
Expand Down
26 changes: 26 additions & 0 deletions examples/tokio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "tokio-minimal"
authors = ["Stefan Lankes <[email protected]>"]
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
tokio = { version = "1.19", default-features = false, features = ["rt", "rt-multi-thread", "macros"] }

[target.'cfg(target_os = "hermit")'.dependencies.hermit-sys]
path = "../../hermit-sys"
default-features = false

[features]
default = ["pci", "pci-ids", "acpi", "dhcpv4", "tcp"]
vga = ["hermit-sys/vga"]
dhcpv4 = ["hermit-sys/dhcpv4"]
pci = ["hermit-sys/pci"]
pci-ids = ["hermit-sys/pci-ids"]
acpi = ["hermit-sys/acpi"]
fsgsbase = ["hermit-sys/fsgsbase"]
smp = ["hermit-sys/smp"]
tcp = ["hermit-sys/tcp"]
instrument = ["hermit-sys/instrument"]
trace = ["hermit-sys/trace"]
20 changes: 20 additions & 0 deletions examples/tokio/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// A minimal tokio example. Network support is currently not supported.

#[cfg(target_os = "hermit")]
use hermit_sys as _;

async fn say_world() {
println!("world");
}

#[tokio::main]
async fn main() {
// Calling `say_world()` does not execute the body of `say_world()`.
let op = say_world();

// This println! comes first
println!("hello");

// Calling `.await` on `op` starts executing `say_world`.
op.await;
}

0 comments on commit 89053d1

Please sign in to comment.