summaryrefslogtreecommitdiff
path: root/core/resources2.rs
diff options
context:
space:
mode:
Diffstat (limited to 'core/resources2.rs')
-rw-r--r--core/resources2.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/core/resources2.rs b/core/resources2.rs
index 62cb3f056..92548a556 100644
--- a/core/resources2.rs
+++ b/core/resources2.rs
@@ -24,6 +24,11 @@ pub trait Resource: Any + 'static {
fn name(&self) -> Cow<str> {
type_name::<Self>().into()
}
+
+ /// Resources may implement the `close()` trait method if they need to do
+ /// resource specific clean-ups, such as cancelling pending futures, after a
+ /// resource has been removed from the resource table.
+ fn close(self: Rc<Self>) {}
}
impl dyn Resource {
@@ -117,7 +122,7 @@ impl ResourceTable {
/// cause the resource to be dropped. However, since resources are reference
/// counted, therefore pending ops are not automatically cancelled.
pub fn close(&mut self, rid: ResourceId) -> Option<()> {
- self.index.remove(&rid).map(|_| ())
+ self.index.remove(&rid).map(|resource| resource.close())
}
/// Returns an iterator that yields a `(id, name)` pair for every resource