Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ar37-rs/flowync
A simple utility for multithreading a/synchronization
https://github.com/ar37-rs/flowync
Last synced: about 2 months ago
JSON representation
A simple utility for multithreading a/synchronization
- Host: GitHub
- URL: https://github.com/ar37-rs/flowync
- Owner: ar37-rs
- License: mit
- Created: 2021-11-26T17:09:02.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-01T04:33:53.000Z (over 2 years ago)
- Last Synced: 2024-10-14T01:35:40.597Z (3 months ago)
- Language: Rust
- Size: 74.2 KB
- Stars: 22
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Flowync
[![Crates.io](https://img.shields.io/crates/v/flowync.svg)](https://crates.io/crates/flowync)
![minimum rustc 1.60.0+](https://img.shields.io/badge/rustc-1.60.0+-blue.svg)
[![CI](https://github.com/Ar37-rs/flowync/actions/workflows/ci.yml/badge.svg)](https://github.com/Ar37-rs/flowync/actions/workflows/ci.yml)
[![Flowync documentation](https://docs.rs/flowync/badge.svg)](https://docs.rs/flowync)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)## Quick Example
```rust
use flowync::{error::{Cause, IOError}, Flower};
type TestFlower = Flower;fn fetch_things(id: usize) -> Result {
let result = Ok::(format!(
"the flower with id: {} successfully completed fetching.",
id
));
let success = result?;
Ok(success)
}fn main() {
let flower: TestFlower = Flower::new(1);
std::thread::spawn({
let handle = flower.handle();
// Activate
handle.activate();
move || {
for i in 0..10 {
// 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,
}
let result = fetch_things(handle.id());
// Set result and then extract later.
handle.set_result(result)
}
});let mut exit = false;
loop {
// Check if the flower is_active()
// and will deactivate itself if the result value successfully received.
if flower.is_active() {
// another logic goes here...
// e.g:
// notify_loading_fn();flower
.poll(|channel| {
if let Some(value) = channel {
println!("{}", value);
}
})
.finalize(|result| {
match result {
Ok(value) => println!("{}", value),
Err(Cause::Suppose(msg)) => {
println!("{}", msg)
}
Err(Cause::Panicked(_msg)) => {
// Handle things if stuff unexpectedly panicked at runtime.
}
}
// Exit if finalized
exit = true;
});
}if exit {
break;
}
}
}
```## More examples
can be found here:
[examples](https://github.com/Ar37-rs/flowync/tree/main/examples) and here:
[eframe tokio (sync/async) integration example](https://github.com/ar37-rs/eframe_tokio_app)