2024-04-24 15:45:54 +08:00
|
|
|
#![cfg(all(feature = "macros", feature = "rt-multi-thread"))]
|
2020-01-21 10:46:32 -08:00
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn basic_main() -> usize {
|
|
|
|
|
1
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-26 18:35:39 +01:00
|
|
|
#[tokio::main]
|
|
|
|
|
async fn generic_fun<T: Default>() -> T {
|
|
|
|
|
T::default()
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 13:44:54 -04:00
|
|
|
#[tokio::main]
|
|
|
|
|
async fn spawning() -> usize {
|
|
|
|
|
let join = tokio::spawn(async { 1 });
|
|
|
|
|
join.await.unwrap()
|
|
|
|
|
}
|
2020-01-21 10:46:32 -08:00
|
|
|
|
2025-07-28 12:59:00 +01:00
|
|
|
#[cfg(tokio_unstable)]
|
|
|
|
|
#[tokio::main(flavor = "local")]
|
|
|
|
|
async fn local_main() -> usize {
|
|
|
|
|
let join = tokio::task::spawn_local(async { 1 });
|
|
|
|
|
join.await.unwrap()
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 13:44:54 -04:00
|
|
|
#[test]
|
|
|
|
|
fn main_with_spawn() {
|
|
|
|
|
assert_eq!(1, spawning());
|
2020-01-21 10:46:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn shell() {
|
|
|
|
|
assert_eq!(1, basic_main());
|
2025-07-28 12:59:00 +01:00
|
|
|
assert_eq!(bool::default(), generic_fun::<bool>());
|
|
|
|
|
|
|
|
|
|
#[cfg(tokio_unstable)]
|
|
|
|
|
assert_eq!(1, local_main());
|
2020-01-21 10:46:32 -08:00
|
|
|
}
|