Skip to content

Commit

Permalink
change: allow IntoFuture for Suspend::new() (closes #3509)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbj committed Jan 31, 2025
1 parent 0073ae7 commit 4e650ba
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tachys/src/reactive_graph/suspense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use reactive_graph::{
use std::{
cell::RefCell,
fmt::Debug,
future::Future,
future::{Future, IntoFuture},
mem,
pin::Pin,
rc::Rc,
Expand Down Expand Up @@ -115,11 +115,15 @@ impl ToAnySubscriber for SuspendSubscriber {

impl<T> Suspend<T> {
/// Creates a new suspended view.
pub fn new(fut: impl Future<Output = T> + Send + 'static) -> Self {
pub fn new<Fut>(fut: Fut) -> Self
where
Fut: IntoFuture<Output = T>,
Fut::IntoFuture: Send + 'static,
{
let subscriber = SuspendSubscriber::new();
let any_subscriber = subscriber.to_any_subscriber();
let inner =
any_subscriber.with_observer(|| Box::pin(ScopedFuture::new(fut)));
let inner = any_subscriber
.with_observer(|| Box::pin(ScopedFuture::new(fut.into_future())));
Self { subscriber, inner }
}
}
Expand Down

0 comments on commit 4e650ba

Please sign in to comment.