Skip to content

Commit

Permalink
Added functionality to set error verbose.
Browse files Browse the repository at this point in the history
  • Loading branch information
ar37-rs committed Sep 27, 2022
1 parent 4af19de commit 6d46e7d
Showing 5 changed files with 24 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Changelog
## [4.6.2] - 2022-9-27
## [4.6.3] - 2022-9-28
- Make Flower uncloneable to avoid any kind of data races, added FlowerState as alternative.
- Internal only: Replace `Option<S, R>` with `TypeOpt<S, R>` managing value of the sync (mtx) state.
- Revert: don't use trait bound `Clone` on type `<S, R>`
- Added functionality to set verboser error message using `fn error_verbose`.

## [4.6.0] - 2022-9-26
- Added 'set_result` and `try_result` fn for more simpler error handling.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flowync"
version = "4.6.2"
version = "4.6.3"
authors = ["Ar37-rs <adyaro37@gmail.com>"]
edition = "2021"
description = "A simple utility for multithreading a/synchronization"
2 changes: 1 addition & 1 deletion examples/tokio_full.rs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ async fn main() {
}
Err(e) => {
// Return error immediately if something not right, for example:
return this.error(e);
return this.error_verbose(e.into());
}
}

2 changes: 1 addition & 1 deletion examples/vectored_tasks.rs
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ fn main() {
}
Err(e) => {
// Return error immediately if something not right, for example:
return this.error(e);
return this.error_verbose(e.into());
}
}

19 changes: 18 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -249,8 +249,18 @@ where
.await
}

/// Set result value
/// Set `Result` value with verboser error message.
///
/// (for more easier to keep in track with the real cause of the error)
pub fn set_result(&self, r: Result<R, Box<dyn Error>>) {
match r {
Ok(val) => self.success(val),
Err(e) => self.error_verbose(e),
}
}

/// Set `Result` value with no verbose (simpler error message)
pub fn set_result_no_verbose(&self, r: Result<R, Box<dyn Error>>) {
match r {
Ok(val) => self.success(val),
Err(e) => self.error(e),
@@ -268,6 +278,13 @@ where
*self.state.mtx.lock().unwrap() = TypeOpt::Error(e.to_string());
self.state.result_ready.store(true, Ordering::Relaxed);
}

/// Set the Err value of the result with more verboser error message.
pub fn error_verbose(&self, e: Box<dyn Error>) {
let err_kind = format!("{:?}", e);
*self.state.mtx.lock().unwrap() = TypeOpt::Error(err_kind);
self.state.result_ready.store(true, Ordering::Relaxed);
}
}

impl<S, R> Clone for Handle<S, R>

0 comments on commit 6d46e7d

Please sign in to comment.