From 60c6ce824c1b19adc86d893053010e1de52c3265 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 22 Dec 2023 12:33:35 +0100 Subject: feat: add support for async constructors --- examples/async/animals/human.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'examples/async') 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, cat: TransientPtr) - -> Self + pub async fn new( + dog: ThreadsafeSingletonPtr, + cat: TransientPtr, + ) -> Self { + // The human needs some rest first + sleep(Duration::from_secs(1)).await; + Self { dog, cat } } } -- cgit v1.2.3-18-g5258