From 7c08d7a5df53fb712929d865d5ef4aacfe26670f Mon Sep 17 00:00:00 2001 From: kjuulh Date: Wed, 7 Aug 2024 12:08:12 +0200 Subject: [PATCH] docs: add a small readme Signed-off-by: kjuulh --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..28cfa08 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# MAD + +Mad is a life-cycle manager for long running rust operations. + +- Webservers +- Queue bindings +- gRPC servers etc +- Cron runners + +It is supposed to be the main thing the application runs, and everything from it is spawned and managed by it. + +```rust +struct WaitServer {} + +#[async_trait] +impl Component for WaitServer { + fn name(&self) -> Option { + Some("NeverEndingRun".into()) + } + + async fn run(&self, cancellation: CancellationToken) -> Result<(), mad::MadError> { + let millis_wait = rand::thread_rng().gen_range(50..1000); + + // Simulates a server running for some time. Is normally supposed to be futures blocking indefinitely + tokio::time::sleep(std::time::Duration::from_millis(millis_wait)).await; + + Ok(()) + } +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + Mad::builder() + .add(WaitServer {}) + .add(WaitServer {}) + .add(WaitServer {}) + .run() + .await?; + + Ok(()) +} +``` +