-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
258 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "flowync" | ||
version = "2.0.7" | ||
version = "3.0.0" | ||
authors = ["Ar37-rs <[email protected]>"] | ||
edition = "2018" | ||
description = "A simple utility for multithreading a/synchronization" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#![allow(clippy::needless_return)] | ||
|
||
use flowync::Flower; | ||
use std::io::Error; | ||
|
||
type TestSimpleFlower = Flower<(), String>; | ||
|
||
fn main() { | ||
let flower: TestSimpleFlower = Flower::new(1); | ||
std::thread::spawn({ | ||
let handle = flower.handle(); | ||
// Activate | ||
handle.activate(); | ||
move || { | ||
let id = handle.id(); | ||
let result = Ok::<String, Error>(format!( | ||
"thse flower with id: {} successfully completed", | ||
id | ||
)); | ||
match result { | ||
Ok(value) => { | ||
// And return ok if the job successfully completed. | ||
return handle.ok(value); | ||
} | ||
Err(e) => { | ||
// Return error immediately if something not right, for example: | ||
return handle.err(e.to_string()); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
let mut exit = false; | ||
|
||
loop { | ||
// Instead of polling the mutex over and over, 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; | ||
}, | ||
); | ||
} | ||
|
||
if exit { | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.