From 73ae2393391f633d3e34aa1dd54743882886de7b Mon Sep 17 00:00:00 2001 From: Justin Moon Date: Sat, 25 Feb 2023 12:37:07 -0600 Subject: [PATCH] cln_plugin: add `shutdown()` method to `Plugin` When plugins receive a "shutdown" notification, then can call this method which will shutdown `cln_plugin`. Then they can await `plugin.join()` and do any remaining cleanup there. This helps avoid a pain-point where plugin authors need to handle 2 separate plugin shutdown mechanisms https://github.com/ElementsProject/lightning/issues/6040 --- plugins/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/src/lib.rs b/plugins/src/lib.rs index a34115a2940f..e6c584ce874b 100644 --- a/plugins/src/lib.rs +++ b/plugins/src/lib.rs @@ -691,6 +691,7 @@ impl Plugin where S: Send + Clone, { + /// Wait for plugin shutdown pub async fn join(&self) -> Result<(), Error> { self.wait_handle .subscribe() @@ -698,6 +699,14 @@ where .await .context("error waiting for shutdown") } + + /// Request plugin shutdown + pub fn shutdown(&self) -> Result<(), Error> { + self.wait_handle + .send(()) + .context("error waiting for shutdown")?; + Ok(()) + } } #[cfg(test)]