mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +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:
committed by
Vincenzo Palazzo
parent
acf01f4c09
commit
57d21206db
@@ -691,6 +691,7 @@ impl<S> Plugin<S>
|
|||||||
where
|
where
|
||||||
S: Send + Clone,
|
S: Send + Clone,
|
||||||
{
|
{
|
||||||
|
/// Wait for plugin shutdown
|
||||||
pub async fn join(&self) -> Result<(), Error> {
|
pub async fn join(&self) -> Result<(), Error> {
|
||||||
self.wait_handle
|
self.wait_handle
|
||||||
.subscribe()
|
.subscribe()
|
||||||
@@ -698,6 +699,14 @@ where
|
|||||||
.await
|
.await
|
||||||
.context("error waiting for shutdown")
|
.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)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user