Skip to content

Commit

Permalink
cln_plugin: add shutdown() method to Plugin
Browse files Browse the repository at this point in the history
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 ElementsProject#6040
  • Loading branch information
justinmoon authored and ddustin committed May 12, 2023
1 parent f21e643 commit 73ae239
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,22 @@ impl<S> Plugin<S>
where
S: Send + Clone,
{
/// Wait for plugin shutdown
pub async fn join(&self) -> Result<(), Error> {
self.wait_handle
.subscribe()
.recv()
.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)]
Expand Down

0 comments on commit 73ae239

Please sign in to comment.