Skip to content

Commit

Permalink
Bring back parking_lot for backward compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
ar37-rs committed Apr 1, 2022
1 parent cab9267 commit 0aee67f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 23 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog
## [2.0.0] - 2022-4-1

## [2.0.x] - 2022-4-1
- Breaking change:
* remove Leaper
* refactor flower
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "flowync"
version = "2.0.2"
version = "2.0.5"
authors = ["Ar37-rs <[email protected]>"]
edition = "2021"
edition = "2018"
description = "A simple utility for multithreading a/synchronization"
documentation = "https://docs.rs/flowync"
readme = "README.md"
Expand All @@ -13,10 +13,10 @@ repository = "https://github.com/Ar37-rs/flowync"

[features]
default = []
use-usync = ["usync"]
parking-lot = ["parking_lot"]

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

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {

// // Return error if the job is failure, for example:
// if i >= 3 {
// return handle.err("Err".to_string());
// return handle.err("Err");
// }
}
// And return ok if the job successfully completed.
Expand Down
6 changes: 3 additions & 3 deletions examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ fn main() {
// or handle.send_async(i).await; can be used from any multithreaded async runtime,

// // Return error if the job is failure, for example:
// if i >= 3 {
// return handle.err("Err".to_string());
// }
if i >= 3 {
return handle.err("Err");
}
}
// And return ok if the job successfully completed.
return handle.ok("Ok".to_string());
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(feature = "use-usync")]
mod usync_mutex;
#[cfg(feature = "use-usync")]
pub use usync_mutex::{Flower, FlowerHandle};
#[cfg(feature = "parking-lot")]
mod parking_lot_mutex;
#[cfg(feature = "parking-lot")]
pub use parking_lot_mutex::{Flower, FlowerHandle};

#[cfg(not(feature = "use-usync"))]
#[cfg(not(feature = "parking-lot"))]
mod std_mutex;
#[cfg(not(feature = "use-usync"))]
#[cfg(not(feature = "parking-lot"))]
pub use std_mutex::{Flower, FlowerHandle};
10 changes: 6 additions & 4 deletions src/usync_mutex.rs → src/parking_lot_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use core::{
sync::atomic::{AtomicBool, Ordering},
task::{Context, Poll, Waker},
};
use parking_lot::{Condvar, Mutex};
use std::{sync::Arc, thread};
use usync::{Condvar, Mutex};

struct FlowerState<SOME, OK>
where
Expand Down Expand Up @@ -76,7 +76,7 @@ where
///
/// // // Return error if the job is failure, for example:
/// // if i >= 3 {
/// // return handle.err("Err".to_string());
/// // return handle.err("Err");
/// // }
/// }
/// // And return ok if the job successfully completed.
Expand Down Expand Up @@ -199,6 +199,8 @@ where
self.state.cvar.notify_one();
}
f(result)
} else {
f(None)
}
self
}
Expand Down Expand Up @@ -325,10 +327,10 @@ where
}

/// Contains the error value for the result.
pub fn err(&self, _value: String) {
pub fn err(&self, _value: impl Into<String>) {
let mut result = self.state.mtx.lock();
let (_, ok, error) = &mut *result;
*error = Some(_value);
*error = Some(_value.into());
*ok = None;
self.state.result_ready.store(true, Ordering::Relaxed);
}
Expand Down
6 changes: 3 additions & 3 deletions src/std_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
///
/// // // Return error if the job is failure, for example:
/// // if i >= 3 {
/// // return handle.err("Err".to_string());
/// // return handle.err("Err");
/// // }
/// }
/// // And return ok if the job successfully completed.
Expand Down Expand Up @@ -325,10 +325,10 @@ where
}

/// Contains the error value for the result.
pub fn err(&self, _value: String) {
pub fn err(&self, _value: impl Into<String>) {
let mut result = self.state.mtx.lock().unwrap();
let (_, ok, error) = &mut *result;
*error = Some(_value);
*error = Some(_value.into());
*ok = None;
self.state.result_ready.store(true, Ordering::Relaxed);
}
Expand Down

0 comments on commit 0aee67f

Please sign in to comment.