darkfid: properly stop rpc client on termination

This commit is contained in:
skoupidi
2024-06-04 16:12:37 +03:00
parent 6b5ae99724
commit ac570e7353

View File

@@ -345,7 +345,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
let task = StoppableTask::new();
task.clone().start(
miner_task(darkfid, recipient, blockchain_config.skip_sync, ex.clone()),
miner_task(darkfid.clone(), recipient, blockchain_config.skip_sync, ex.clone()),
|res| async move {
match res {
Ok(()) | Err(Error::MinerTaskStopped) => { /* Do nothing */ }
@@ -360,7 +360,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
} else {
let task = StoppableTask::new();
task.clone().start(
consensus_task(darkfid, ex.clone()),
consensus_task(darkfid.clone(), ex.clone()),
|res| async move {
match res {
Ok(()) | Err(Error::ConsensusTaskStopped) => { /* Do nothing */ }
@@ -392,5 +392,10 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
let flushed_bytes = sled_db.flush_async().await?;
info!(target: "darkfid", "Flushed {} bytes", flushed_bytes);
if let Some(ref rpc_client) = darkfid.rpc_client {
info!(target: "darkfid", "Stopping JSON-RPC client...");
rpc_client.lock().await.client.stop().await;
};
Ok(())
}