Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
ar37-rs committed Oct 1, 2022
1 parent 895cd66 commit 402727c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog
## [5.0.1] - 2022-10-1
## [5.1.0] - 2022-10-1
- Clean up code.
- On Error: Support handling unexpected panic at runtime.
- Added CompactFlower, a Flower with composable error message (can be enabled using `features = ["compact"]` )

Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flowync"
version = "5.0.1"
version = "5.1.0"
authors = ["Ar37-rs <[email protected]>"]
edition = "2021"
description = "A simple utility for multithreading a/synchronization"
Expand All @@ -12,6 +12,7 @@ repository = "https://github.com/Ar37-rs/flowync"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["compact"]
compact = []

[[example]]
Expand Down
12 changes: 6 additions & 6 deletions examples/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum ErrMessage {
Other,
}

type TestFlower = CompactFlower<u32, String, ErrMessage>;
type TestCompactFlower = CompactFlower<u32, String, ErrMessage>;

fn fetch_things(id: usize) -> Result<String, IOError> {
let result = Ok::<String, IOError>(format!(
Expand All @@ -22,9 +22,9 @@ fn fetch_things(id: usize) -> Result<String, IOError> {
}

fn main() {
let flower: TestFlower = CompactFlower::new(1);
let compact_flower: TestCompactFlower = CompactFlower::new(1);
std::thread::spawn({
let handle = flower.handle();
let handle = compact_flower.handle();
// Activate
handle.activate();
move || {
Expand All @@ -47,14 +47,14 @@ fn main() {
let mut exit = false;

loop {
// Check if the flower is_active()
// Check if the compact flower is_active()
// and will deactivate itself if the result value successfully received.
if flower.is_active() {
if compact_flower.is_active() {
// another logic goes here...
// e.g:
// notify_loading_fn();

flower
compact_flower
.poll(|channel| {
if let Some(value) = channel {
println!("{}", value);
Expand Down
7 changes: 6 additions & 1 deletion src/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum CompactTypeOpt<S, R, E>
where
S: Send,
R: Send,
E: Send,
{
Channel(S),
Success(R),
Expand All @@ -25,6 +26,7 @@ impl<S, R, E> Default for CompactTypeOpt<S, R, E>
where
S: Send,
R: Send,
E: Send,
{
fn default() -> Self {
Self::None
Expand All @@ -35,7 +37,7 @@ impl<S, R, E> Debug for CompactTypeOpt<S, R, E>
where
S: Send + Debug,
R: Send + Debug,
E: std::fmt::Debug,
E: Send + Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Expand All @@ -51,6 +53,7 @@ impl<S, R, E> CompactTypeOpt<S, R, E>
where
S: Send,
R: Send,
E: Send,
{
fn take(&mut self) -> Self {
mem::take(self)
Expand All @@ -61,6 +64,7 @@ struct InnerState<S, R, E>
where
S: Send,
R: Send,
E: Send,
{
activated: AtomicBool,
result_ready: AtomicBool,
Expand Down Expand Up @@ -92,6 +96,7 @@ impl<S, R, E> Drop for InnerState<S, R, E>
where
S: Send,
R: Send,
E: Send,
{
fn drop(&mut self) {}
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ where

impl<S, R> Debug for InnerState<S, R>
where
S: Debug + Send,
R: Debug + Send,
S: Send + Debug,
R: Send + Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("InnerState")
Expand Down Expand Up @@ -311,8 +311,8 @@ where

impl<S, R> Debug for Handle<S, R>
where
S: Debug + Send,
R: Debug + Send,
S: Send + Debug,
R: Send + Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Handle")
Expand Down Expand Up @@ -597,8 +597,8 @@ where

impl<S, R> Debug for Flower<S, R>
where
S: Debug + Send,
R: Debug + Send,
S: Send + Debug,
R: Send + Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Flower")
Expand Down

0 comments on commit 402727c

Please sign in to comment.