mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
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
This commit is contained in:
parent
acf01f4c09
commit
57d21206db
@ -691,6 +691,7 @@ impl<S> Plugin<S>
|
||||
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)]
|
||||
|
Loading…
Reference in New Issue
Block a user