Compare commits

...

4 Commits
v0.3.0 ... main

Author SHA1 Message Date
b78423377c
docs: add examples
All checks were successful
continuous-integration/drone/push Build is passing
this is to show how we can use closures in the mad component context. It isn't super pretty because of the async closure, so we need to show the slighly complicated syntax

Signed-off-by: kjuulh <contact@kjuulh.io>
2024-08-07 17:09:52 +02:00
1446f4c3cf chore(release): v0.4.0 (#5)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
### Added
- add correction
- add small docs

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: #5
2024-08-07 16:51:15 +02:00
8a80480d94
feat: add correction
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-08-07 16:44:23 +02:00
b7b2992730
feat: add small docs
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-08-07 16:44:12 +02:00
6 changed files with 39 additions and 4 deletions

View File

@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.4.0] - 2024-08-07
### Added
- add correction
- add small docs
## [0.3.0] - 2024-08-07 ## [0.3.0] - 2024-08-07
### Added ### Added

2
Cargo.lock generated
View File

@ -236,7 +236,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]] [[package]]
name = "mad" name = "mad"
version = "0.2.0" version = "0.3.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",

View File

@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
version = "0.3.0" version = "0.4.0"
[workspace.dependencies] [workspace.dependencies]
mad = { path = "crates/mad" } mad = { path = "crates/mad" }

View File

@ -41,3 +41,11 @@ async fn main() -> anyhow::Result<()> {
} }
``` ```
## Examples
Can be found (here)[crates/mad/examples]
- basic
- fn
- signals
- error_log

View File

@ -10,7 +10,7 @@ impl mad::Component for WaitServer {
Some("WaitServer".into()) Some("WaitServer".into())
} }
async fn run(&self, cancellation: CancellationToken) -> Result<(), mad::MadError> { async fn run(&self, _cancellation: CancellationToken) -> Result<(), mad::MadError> {
let millis_wait = rand::thread_rng().gen_range(500..3000); let millis_wait = rand::thread_rng().gen_range(500..3000);
tracing::debug!("waiting: {}ms", millis_wait); tracing::debug!("waiting: {}ms", millis_wait);
@ -28,9 +28,11 @@ async fn main() -> anyhow::Result<()> {
.with_max_level(Level::TRACE) .with_max_level(Level::TRACE)
.init(); .init();
let item = "some item".to_string();
mad::Mad::builder() mad::Mad::builder()
.add(WaitServer {}) .add(WaitServer {})
.add_fn(|cancel| async move { .add_fn(|_cancel| async move {
let millis_wait = 50; let millis_wait = 50;
tracing::debug!("waiting: {}ms", millis_wait); tracing::debug!("waiting: {}ms", millis_wait);
@ -40,6 +42,24 @@ async fn main() -> anyhow::Result<()> {
Ok(()) Ok(())
}) })
.add_fn(move |_cancel| {
// I am an actual closure
let item = item.clone();
async move {
let _item = item;
let millis_wait = 50;
tracing::debug!("waiting: {}ms", millis_wait);
// 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(())
}
})
.run() .run()
.await?; .await?;

View File

@ -94,6 +94,7 @@ impl Mad {
let close_result = self.close_components().await; let close_result = self.close_components().await;
tracing::info!("mad is closed down");
match (run_result, close_result) { match (run_result, close_result) {
(Err(run), Err(close)) => { (Err(run), Err(close)) => {
return Err(MadError::AggregateError(AggregateError { return Err(MadError::AggregateError(AggregateError {