diff options
| author | HampusM <hampus@hampusmat.com> | 2023-08-04 15:24:32 +0200 | 
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2023-08-04 15:25:58 +0200 | 
| commit | 14e45fe9aa2431120cfd6a7240f8bb94e45e730d (patch) | |
| tree | 72bceb0580801ec1d59fc7f79e609f0ac7c53681 /examples/async-factory | |
| parent | dce6bfc2321c0041fef5a2cb368ff45ba089198b (diff) | |
refactor!: remove async_closure macro from API
BREAKING CHANGE: The async_closure macro has been removed. This is because it is completely out of scope for this crate
Diffstat (limited to 'examples/async-factory')
| -rw-r--r-- | examples/async-factory/main.rs | 22 | 
1 files changed, 13 insertions, 9 deletions
| diff --git a/examples/async-factory/main.rs b/examples/async-factory/main.rs index b9beded..76efb2f 100644 --- a/examples/async-factory/main.rs +++ b/examples/async-factory/main.rs @@ -7,7 +7,7 @@ use std::time::Duration;  use anyhow::Result;  use syrette::di_container::asynchronous::prelude::*;  use syrette::ptr::TransientPtr; -use syrette::{async_closure, declare_default_factory, factory}; +use syrette::{declare_default_factory, factory};  use tokio::time::sleep;  trait IFoo: Send + Sync @@ -77,10 +77,12 @@ async fn main() -> Result<()>      di_container          .bind::<IFooFactory>()          .to_async_factory(&|_| { -            async_closure!(|cnt| { -                let foo_ptr = Box::new(Foo::new(cnt)); +            Box::new(|cnt| { +                Box::pin(async move { +                    let foo_ptr = Box::new(Foo::new(cnt)); -                foo_ptr as Box<dyn IFoo> +                    foo_ptr as Box<dyn IFoo> +                })              })          })          .await?; @@ -88,13 +90,15 @@ async fn main() -> Result<()>      di_container          .bind::<dyn IPerson>()          .to_async_default_factory(&|_| { -            async_closure!(|| { -                // Do some time demanding thing... -                sleep(Duration::from_secs(1)).await; +            Box::new(|| { +                Box::pin(async { +                    // Do some time demanding thing... +                    sleep(Duration::from_secs(1)).await; -                let person = TransientPtr::new(Person::new("Bob".to_string())); +                    let person = TransientPtr::new(Person::new("Bob".to_string())); -                person as TransientPtr<dyn IPerson> +                    person as TransientPtr<dyn IPerson> +                })              })          })          .await?; | 
