Skip to content

Commit

Permalink
Merge pull request #15 from elsirion/2024-02-shutdown
Browse files Browse the repository at this point in the history
fix: listen for shutdown signal
  • Loading branch information
elsirion authored Aug 19, 2024
2 parents 9d12175 + 8528455 commit dd444f2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use uuid::Uuid;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let (shutdown_sender, mut shutdown_receiver) = tokio::sync::mpsc::channel::<()>(1);
let plugin = if let Some(plugin) = cln_plugin::Builder::new(stdin(), stdout())
.option(ConfigOption::new(
"clnurl_listen",
Expand Down Expand Up @@ -53,6 +54,17 @@ async fn main() -> anyhow::Result<()> {
Value::OptString,
"Nostr pub key of zapper",
))
.subscribe("shutdown", move |_, _| {
let shutdown_sender_inner = shutdown_sender.clone();
async move {
shutdown_sender_inner
.send(())
.await
.expect("Shutdown signal received after main thread died");

Ok(())
}
})
.dynamic()
.start(())
.await?
Expand Down Expand Up @@ -124,8 +136,13 @@ async fn main() -> anyhow::Result<()> {
.route("/invoice", get(get_invoice))
.with_state(state);

let shutdown_future = async move {
shutdown_receiver.recv().await;
};

axum::Server::bind(&listen_addr)
.serve(lnurl_service.into_make_service())
.with_graceful_shutdown(shutdown_future)
.await?;

Ok(())
Expand Down

0 comments on commit dd444f2

Please sign in to comment.