7
crates/cuddle-lazy/Cargo.toml
Normal file
7
crates/cuddle-lazy/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "cuddle-lazy"
|
||||
edition = "2021"
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
29
crates/cuddle-lazy/src/lib.rs
Normal file
29
crates/cuddle-lazy/src/lib.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use std::{future::Future, ops::Deref, pin::Pin, sync::Arc};
|
||||
|
||||
pub struct LazyResolve(
|
||||
Arc<dyn Fn() -> Pin<Box<dyn Future<Output = anyhow::Result<()>> + Send>> + Send + Sync>,
|
||||
);
|
||||
|
||||
impl LazyResolve {
|
||||
pub fn new(
|
||||
func: Box<
|
||||
dyn Fn() -> Pin<Box<dyn Future<Output = anyhow::Result<()>> + Send>> + Send + Sync,
|
||||
>,
|
||||
) -> Self {
|
||||
Self(Arc::new(func))
|
||||
}
|
||||
|
||||
pub async fn call(&self) -> anyhow::Result<()> {
|
||||
// Bad hack until .call becomes stable
|
||||
(self.0)().await
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for LazyResolve {
|
||||
type Target =
|
||||
Arc<dyn Fn() -> Pin<Box<dyn Future<Output = anyhow::Result<()>> + Send>> + Send + Sync>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user