aboutsummaryrefslogtreecommitdiff
path: root/examples/async/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/async/main.rs')
-rw-r--r--examples/async/main.rs52
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(())
+}