From 080cc42bb1da09059dbc35049a7ded0649961e0c Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 29 Aug 2022 20:52:56 +0200 Subject: feat: implement async functionality --- examples/async/main.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/async/main.rs (limited to 'examples/async/main.rs') 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::() + .await? + .threadsafe_singleton()?; + + dog.woof(); + } + + spawn(async move { + let human = di_container + .lock() + .await + .get::() + .await? + .transient()?; + + human.make_pets_make_sounds(); + + Ok::<_, anyhow::Error>(()) + }) + .await??; + + Ok(()) +} -- cgit v1.2.3-18-g5258