Skip to content

Commit

Permalink
Bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
ar37-rs committed Sep 25, 2022
1 parent 3c472eb commit 3f867e2
Show file tree
Hide file tree
Showing 11 changed files with 514 additions and 927 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog
## [4.0.0] - 2022-9-25
- Refactor
* `ok` fn changed to `success` fn, and `err` fn changed to `error` fn for more convenience.
* Added `result` and `extract` fn
* Remove `then` fn
* Remove parking_lot as dependency.

## [3.0.0] - 2022-4-6
- Remove needless traits: Sync + 'static
Expand Down
12 changes: 2 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "flowync"
version = "3.0.0"
version = "4.0.0"
authors = ["Ar37-rs <[email protected]>"]
edition = "2018"
edition = "2021"
description = "A simple utility for multithreading a/synchronization"
documentation = "https://docs.rs/flowync"
readme = "README.md"
Expand All @@ -11,13 +11,5 @@ license = "MIT OR Apache-2.0"
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 = []
parking-lot = ["parking_lot"]

[dependencies.parking_lot]
version = "0.12"
optional = true

[dev-dependencies]
tokio = { version = "1", features = ["full"] }
33 changes: 14 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Flowync

[![Crates.io](https://img.shields.io/crates/v/flowync.svg)](https://crates.io/crates/flowync)
![minimum rustc 1.61.0](https://img.shields.io/badge/rustc-1.61.0-blue.svg)
[![Flowync documentation](https://docs.rs/flowync/badge.svg)](https://docs.rs/flowync)
[![CI](https://github.com/Ar37-rs/flowync/actions/workflows/ci.yml/badge.svg)](https://github.com/Ar37-rs/flowync/actions/workflows/ci.yml)

## Quick Example

```rust

use flowync::Flower;

type TestFlower = Flower<u32, String>;

fn main() {
Expand All @@ -20,50 +19,46 @@ fn main() {
handle.activate();
move || {
for i in 0..10 {
// // Send current value through channel, will block the spawned thread
// Send current value through channel, will block the spawned thread
// until the option value successfully being polled in the main thread.
handle.send(i);
// or handle.send_async(i).await; can be used from any multithreaded async runtime,

// // Return error if the job is failure, for example:
// Return error if the job is failure, for example:
// if i >= 3 {
// return handle.err("Err");
// return handle.error("Err");
// }
}
// And return ok if the job successfully completed.
return handle.ok("Ok".to_string());
// And return if the job successfully completed.
return handle.success("Ok".to_string());
}
});

let mut exit = false;

loop {
// Instead of polling the mutex over and over, check if the flower is_active()
// Check if the flower is_active()
// and will deactivate itself if the result value successfully received.
// Note: this fn is non-blocking (won't block the current thread).
if flower.is_active() {
// another logic goes here...
// e.g:
// notify_loading_fn();

flower.then(
|channel| {
// poll channel
flower
.extract(|channel| {
// Poll channel
if let Some(value) = channel {
println!("{}", value);
}
},
|result| {
// match result
})
.finalize(|result| {
match result {
Ok(value) => println!("{}", value),
Err(err_msg) => println!("{}", err_msg),
}

// exit if completed
// Exit if finalized
exit = true;
},
);
});
}

if exit {
Expand Down
32 changes: 13 additions & 19 deletions examples/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![allow(clippy::needless_return)]

use flowync::Flower;

type TestFlower = Flower<u32, String>;

fn main() {
Expand All @@ -12,50 +10,46 @@ fn main() {
handle.activate();
move || {
for i in 0..10 {
// // Send current value through channel, will block the spawned thread
// Send current value through channel, will block the spawned thread
// until the option value successfully being polled in the main thread.
handle.send(i);
// or handle.send_async(i).await; can be used from any multithreaded async runtime,

// // Return error if the job is failure, for example:
// Return error if the job is failure, for example:
// if i >= 3 {
// return handle.err("Err");
// return handle.error("Err");
// }
}
// And return ok if the job successfully completed.
return handle.ok("Ok".to_string());
// And return if the job successfully completed.
return handle.success("Ok".to_string());
}
});

let mut exit = false;

loop {
// Instead of polling the mutex over and over, check if the flower is_active()
// Check if the flower is_active()
// and will deactivate itself if the result value successfully received.
// Note: this fn is non-blocking (won't block the current thread).
if flower.is_active() {
// another logic goes here...
// e.g:
// notify_loading_fn();

flower.then(
|channel| {
// poll channel
flower
.extract(|channel| {
// Poll channel
if let Some(value) = channel {
println!("{}", value);
}
},
|result| {
// match result
})
.finalize(|result| {
match result {
Ok(value) => println!("{}", value),
Err(err_msg) => println!("{}", err_msg),
}

// exit if completed
// Exit if finalized
exit = true;
},
);
});
}

if exit {
Expand Down
26 changes: 11 additions & 15 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ fn main() {
));
match result {
Ok(value) => {
// And return ok if the job successfully completed.
return handle.ok(value);
// And return if the job successfully completed.
return handle.success(value);
}
Err(e) => {
// Return error immediately if something not right, for example:
return handle.err(e.to_string());
return handle.error(e);
}
}
}
Expand All @@ -33,20 +33,16 @@ fn main() {
let mut exit = false;

loop {
// Instead of polling the mutex over and over, check if the flower is_active()
// Check if the flower is_active()
// and will deactivate itself if the result value successfully received.
// Note: this fn is non-blocking (won't block the current thread).
if flower.is_active() {
flower.then(
|_channel| (),
|result| {
match result {
Ok(value) => println!("{}", value),
Err(err_msg) => println!("{}", err_msg),
}
exit = true;
},
);
flower.result(|result| {
match result {
Ok(value) => println!("{}", value),
Err(err_msg) => println!("{}", err_msg),
}
exit = true;
});
}

if exit {
Expand Down
26 changes: 13 additions & 13 deletions examples/tokio_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn main() {
}
Err(e) => {
// Return error immediately if something not right, for example:
return this.err(e.to_string());
return this.error(e);
}
}

Expand All @@ -38,12 +38,12 @@ async fn main() {
if this.should_cancel() {
let value = format!("canceling the flower with id: {}", id);
this.send_async(value).await;
return this.err(format!("the flower with id: {} canceled", id));
return this.error(format!("the flower with id: {} canceled", id));
}

// Finishing
// either return this.ok(instant.elapsed().subsec_micros()); or
this.ok(instant.elapsed().subsec_micros());
// Finalizing
// either `return this.success(instant.elapsed().subsec_micros());` or
this.success(instant.elapsed().subsec_micros());
// both are ok
}
});
Expand All @@ -52,13 +52,14 @@ async fn main() {

loop {
if flower.is_active() {
flower.then(
|channel| {
flower
.extract(|channel| {
// Poll channel
if let Some(value) = channel {
println!("{}\n", value);
println!("{}", value);
}
},
|result| {
})
.finalize(|result| {
match result {
Ok(elapsed) => println!(
"the flower with id: {} finished in: {:?} microseconds \n",
Expand All @@ -68,11 +69,10 @@ async fn main() {
Err(err_msg) => println!("{}", err_msg),
}
done = true;
},
);
});
}

// // Cancel if need to
// Cancel if need to
// flower.cancel();

if done {
Expand Down
24 changes: 12 additions & 12 deletions examples/vectored_flowers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ fn main() {
move || {
let id = this.id();

// // Panic if need to.
// Panic if need to.
// if id == 3 {
// std::panic::panic_any("loudness");
// std::panic::panic_any("loudness");
// }

let millis = id + 1;
Expand All @@ -37,7 +37,7 @@ fn main() {
}
Err(e) => {
// Return error immediately if something not right, for example:
return this.err(e.to_string());
return this.error(e);
}
}

Expand All @@ -46,12 +46,12 @@ fn main() {
if this.should_cancel() {
let value = format!("canceling the flower with id: {}", id);
this.send(value);
return this.err(format!("the flower with id: {} canceled", id));
return this.error(format!("the flower with id: {} canceled", id));
}

// Finishing
// either return this.ok(instant.elapsed().subsec_millis()); or
this.ok(instant.elapsed().subsec_millis());
this.success(instant.elapsed().subsec_millis());
// both are ok
}
});
Expand All @@ -72,13 +72,14 @@ fn main() {
// }

let mut done = false;
flower.then(
|channel| {
flower
.extract(|channel| {
// Poll channel
if let Some(value) = channel {
println!("{}\n", value);
println!("{}", value);
}
},
|result| {
})
.finalize(|result| {
match result {
Ok(elapsed) => println!(
"the flower with id: {} finished in: {:?} milliseconds\n",
Expand All @@ -87,8 +88,7 @@ fn main() {
Err(err_msg) => println!("{}", err_msg),
}
done = true;
},
);
});

if done {
// Set to None to free later
Expand Down
Loading

0 comments on commit 3f867e2

Please sign in to comment.