This commit is contained in:
JMARyA 2025-04-27 19:26:34 +02:00
parent dcebded8a3
commit 10e5c77454
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 6 additions and 7 deletions

View file

@ -9,8 +9,9 @@ fn main() {
let (input, output) = rally(items, |item: &_| { let (input, output) = rally(items, |item: &_| {
std::thread::sleep(Duration::from_millis(item * 100)); std::thread::sleep(Duration::from_millis(item * 100));
return 0; return Some(0);
}); })
.unwrap();
println!("RALLY RESULTS: {input:?} -> {output:?}"); println!("RALLY RESULTS: {input:?} -> {output:?}");
} }

View file

@ -27,7 +27,7 @@ pub static UNION: Lazy<
/// Rally Function /// Rally Function
/// ///
/// This executes a thread for every item executing `f(&item) -> X`. Whatever function returns first is returned while every other thread is killed. /// This executes a thread for every item executing `f(&item) -> X`. Whatever function returns first is returned while every other thread is killed.
pub fn rally<T: Send + Sync + 'static, F, X: Send + 'static>(items: Vec<T>, f: F) -> (T, X) pub fn rally<T: Send + Sync + 'static, F, X: Send + 'static>(items: Vec<T>, f: F) -> Option<(T, X)>
where where
F: Fn(&T) -> Option<X> + Send + Sync + Copy + 'static, F: Fn(&T) -> Option<X> + Send + Sync + Copy + 'static,
{ {
@ -67,11 +67,11 @@ where
log::info!("Rally ended with {items_len} items in {elapsed:?}"); log::info!("Rally ended with {items_len} items in {elapsed:?}");
return (fastest_item, fastest_result.unwrap()); return Some((fastest_item, fastest_result.unwrap()));
} }
} }
panic!("No useable results in rally") None
} }
pub fn retry<O, F: Fn() -> Option<O>>(f: F) -> O { pub fn retry<O, F: Fn() -> Option<O>>(f: F) -> O {

View file

@ -61,8 +61,6 @@ pub struct ServiceManager {
pub mode: ServiceMode, pub mode: ServiceMode,
} }
// TODO : impl decay mode
/// The mode on which services should operate /// The mode on which services should operate
pub enum ServiceMode { pub enum ServiceMode {
/// Behave like a daemon. Services can never die and will come back to life after beeing killed. They will always haunt you. /// Behave like a daemon. Services can never die and will come back to life after beeing killed. They will always haunt you.