diff options
author | HampusM <hampus@hampusmat.com> | 2022-08-29 20:52:56 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-08-29 21:01:32 +0200 |
commit | 080cc42bb1da09059dbc35049a7ded0649961e0c (patch) | |
tree | 307ee564124373616022c1ba2b4d5af80845cd92 /examples/async/main.rs | |
parent | 6e31d8f9e46fece348f329763b39b9c6f2741c07 (diff) |
feat: implement async functionality
Diffstat (limited to 'examples/async/main.rs')
-rw-r--r-- | examples/async/main.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/async/main.rs b/examples/async/main.rs new file mode 100644 index 0000000..f72ff39 --- /dev/null +++ b/examples/async/main.rs @@ -0,0 +1,52 @@ +#![deny(clippy::all)] +#![deny(clippy::pedantic)] +#![allow(clippy::module_name_repetitions)] + +use std::sync::Arc; + +use anyhow::Result; +use tokio::spawn; +use tokio::sync::Mutex; + +mod animals; +mod bootstrap; +mod interfaces; + +use bootstrap::bootstrap; +use interfaces::dog::IDog; +use interfaces::human::IHuman; + +#[tokio::main] +async fn main() -> Result<()> +{ + println!("Hello, world!"); + + let di_container = Arc::new(Mutex::new(bootstrap().await?)); + + { + let dog = di_container + .lock() + .await + .get::<dyn IDog>() + .await? + .threadsafe_singleton()?; + + dog.woof(); + } + + spawn(async move { + let human = di_container + .lock() + .await + .get::<dyn IHuman>() + .await? + .transient()?; + + human.make_pets_make_sounds(); + + Ok::<_, anyhow::Error>(()) + }) + .await??; + + Ok(()) +} |