fix: abort when leaving *this* owner, but don't force it if already complete
This commit is contained in:
parent
dcc43e574b
commit
a51faea9a9
|
@ -91,7 +91,6 @@ use std::{future::Future, panic::Location, pin::Pin, sync::Arc};
|
|||
/// let action3 = ArcAction::new(|input: &(usize, String)| async { todo!() });
|
||||
/// ```
|
||||
pub struct ArcAction<I, O> {
|
||||
orig_owner: Option<Owner>,
|
||||
in_flight: ArcRwSignal<usize>,
|
||||
input: ArcRwSignal<Option<I>>,
|
||||
value: ArcRwSignal<Option<O>>,
|
||||
|
@ -107,7 +106,6 @@ pub struct ArcAction<I, O> {
|
|||
impl<I, O> Clone for ArcAction<I, O> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
orig_owner: self.orig_owner.clone(),
|
||||
in_flight: self.in_flight.clone(),
|
||||
input: self.input.clone(),
|
||||
value: self.value.clone(),
|
||||
|
@ -191,7 +189,6 @@ where
|
|||
Fu: Future<Output = O> + Send + 'static,
|
||||
{
|
||||
ArcAction {
|
||||
orig_owner: Owner::current(),
|
||||
in_flight: ArcRwSignal::new(0),
|
||||
input: Default::default(),
|
||||
value: ArcRwSignal::new(value),
|
||||
|
@ -216,16 +213,12 @@ where
|
|||
|
||||
// abort this task if the owner is cleaned up
|
||||
let (abort_tx, mut abort_rx) = oneshot::channel();
|
||||
if let Some(owner) = &self.orig_owner {
|
||||
owner.with(|| {
|
||||
Owner::on_cleanup(move || {
|
||||
// If this fails, it is because the receiver has already dropped, i.e.,
|
||||
// because the dispatched task has already completed. This means it can be
|
||||
// safely ignored, because it doesn't need to be aborted in any case.
|
||||
let _ = abort_tx.send(());
|
||||
})
|
||||
});
|
||||
}
|
||||
Owner::on_cleanup(move || {
|
||||
// If this fails, it is because the receiver has already dropped, i.e.,
|
||||
// because the dispatched task has already completed. This means it can be
|
||||
// safely ignored, because it doesn't need to be aborted in any case.
|
||||
let _ = abort_tx.send(());
|
||||
});
|
||||
|
||||
// Update the state before loading
|
||||
self.in_flight.update(|n| *n += 1);
|
||||
|
@ -351,7 +344,6 @@ where
|
|||
{
|
||||
let action_fn = SendWrapper::new(action_fn);
|
||||
ArcAction {
|
||||
orig_owner: Owner::current(),
|
||||
in_flight: ArcRwSignal::new(0),
|
||||
input: Default::default(),
|
||||
value: ArcRwSignal::new(value),
|
||||
|
|
Loading…
Reference in New Issue