Macro darkfi::async_daemonize
source · macro_rules! async_daemonize { ($realmain:ident) => { ... }; }
Expand description
This macro is used for a standard way of daemonizing darkfi binaries with TOML config file configuration, and argument parsing. It also spawns a multithreaded async executor and passes it into the given function.
The Cargo.toml dependencies needed for this are:
async-std = "1.12.0"
darkfi = { path = "../../", features = ["util"] }
easy-parallel = "3.2.0"
simplelog = "0.12.0"
smol = "1.2.5"
# Argument parsing
serde = {version = "1.0.135", features = ["derive"]}
structopt = "0.3.26"
structopt-toml = "0.5.1"
Example usage:
use async_std::sync::Arc;
use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
const CONFIG_FILE: &str = "daemond_config.toml";
const CONFIG_FILE_CONTENTS: &str = include_str!("../daemond_config.toml");
#[derive(Clone, Debug, Deserialize, StructOpt, StructOptToml)]
#[serde(default)]
#[structopt(name = "daemond", about = cli_desc!())]
struct Args {
#[structopt(short, long)]
/// Configuration file to use
config: Option<String>,
#[structopt(short, parse(from_occurrences))]
/// Increase verbosity (-vvv supported)
verbose: u8,
}
async_daemonize!(realmain);
async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
println!("Hello, world!");
Ok(())
}