aboutsummaryrefslogtreecommitdiff
path: root/examples/async/animals/human.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-12-22 12:33:35 +0100
committerHampusM <hampus@hampusmat.com>2023-12-22 12:50:58 +0100
commit60c6ce824c1b19adc86d893053010e1de52c3265 (patch)
treeeaa40fbe578a58ff8f40b4a993335d39254aa5c0 /examples/async/animals/human.rs
parent0f2756536e8fc311119da2af5b4dcc33f41bec6e (diff)
feat: add support for async constructors
Diffstat (limited to 'examples/async/animals/human.rs')
-rw-r--r--examples/async/animals/human.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/examples/async/animals/human.rs b/examples/async/animals/human.rs
index fc98ed8..5bc4903 100644
--- a/examples/async/animals/human.rs
+++ b/examples/async/animals/human.rs
@@ -1,5 +1,8 @@
+use std::time::Duration;
+
use syrette::injectable;
use syrette::ptr::{ThreadsafeSingletonPtr, TransientPtr};
+use tokio::time::sleep;
use crate::interfaces::cat::ICat;
use crate::interfaces::dog::IDog;
@@ -14,9 +17,14 @@ pub struct Human
#[injectable(IHuman, async = true)]
impl Human
{
- pub fn new(dog: ThreadsafeSingletonPtr<dyn IDog>, cat: TransientPtr<dyn ICat>)
- -> Self
+ pub async fn new(
+ dog: ThreadsafeSingletonPtr<dyn IDog>,
+ cat: TransientPtr<dyn ICat>,
+ ) -> Self
{
+ // The human needs some rest first
+ sleep(Duration::from_secs(1)).await;
+
Self { dog, cat }
}
}