Skip to content

Commit f777cd3

Browse files
committed
Clean exit
1 parent 30d5af2 commit f777cd3

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/main.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,7 @@ fn help() {
407407
println!(" nodeinfo");
408408
}
409409

410-
#[tokio::main]
411-
async fn main() {
410+
fn main() {
412411
let package_version = env!("CARGO_PKG_VERSION");
413412
let package_name = env!("CARGO_PKG_NAME");
414413
println!("App+version: {} v{}", package_name, package_version);
@@ -450,14 +449,20 @@ async fn main() {
450449
println!(" Listen address: \t{}", get_listen_address(&node));
451450
println!(" Network: \t{}", settings.network);
452451

453-
let handle = tokio::runtime::Handle::current();
452+
// tokio runtime for spawning in background (event handler)
453+
let runtime = tokio::runtime::Runtime::new().unwrap();
454454
let node_clone = node.clone();
455-
handle.spawn(async move {
455+
let event_loop_handle = runtime.handle().spawn(async move {
456456
handle_events(&node_clone);
457457
});
458458

459+
// handle interactive commands
459460
poll_for_user_input(&node);
460461

462+
event_loop_handle.abort();
463+
461464
node.stop().unwrap();
462465
println!("Node stopped");
466+
467+
runtime.shutdown_timeout(std::time::Duration::from_millis(1000));
463468
}

0 commit comments

Comments
 (0)