summaryrefslogtreecommitdiff
path: root/core/resources2.rs
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2020-12-03 23:52:55 +0100
committerBert Belder <bertbelder@gmail.com>2020-12-09 15:58:36 +0100
commitb200e6fc3e591f67646832adb9bbf129ee2b2761 (patch)
treeb04c877ee5c66ebcf3b611b2ca5c743d0c7374ec /core/resources2.rs
parentb1379b7de3045000c1f4fd76a503b4e639946348 (diff)
core: add plumbing for canceling ops when closing a resource (#8661)
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