fix: Use Rc for lifecycle management (#4471)

* fix: Use Rc for lifecycle management

* Try to unwrap the Rc instead of using both rc and option

* Add a test for use drop

* fix test name

---------

Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
yydcnjjwandEvan Almloff authored and GitHub committed 2025-08-06 10:30:36 -05:00
1 parent 79e7739bee
commit a610aaefc3
2 files changed
+72 -9

No files matched your search

+5 -9
View File
@@ -4,6 +4,7 @@ use crate::{
Task,
};
use std::future::Future;
use std::rc::Rc;
use std::sync::Arc;
/// Get the current scope id
@@ -441,15 +442,10 @@ pub fn use_drop<D: FnOnce() + 'static>(destroy: D) {
}
}
// We need to impl clone for the lifecycle, but we don't want the drop handler for the closure to be called twice.
impl<D: FnOnce()> Clone for LifeCycle<D> {
fn clone(&self) -> Self {
Self { ondestroy: None }
}
}
use_hook(|| LifeCycle {
ondestroy: Some(destroy),
use_hook(|| {
Rc::new(LifeCycle {
ondestroy: Some(destroy),
})
});
}