diff --git a/CHANGELOG.md b/CHANGELOG.md index d294fd3..b85217f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], and this project aims to follow [Semantic Versioning]. +## [0.3.0] - 2024-09-13 + +### Changed + +- `spawn` and `spawn_local` features removed, use of `spawn_local` was improper in multithread environments. Now simple `spawn` is + generaly available feature. + ## [0.2.0] - 2024-05-07 ### Added diff --git a/Cargo.toml b/Cargo.toml index 1b3ac18..0bc31cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "futures-signals-ext" -version = "0.2.0" +version = "0.3.0" authors = ["martin.kolarik@smartcontrol.cz"] description = "Extension to futures-signals: MutableOption with combinators, spawning, predicate driven selections from SignalVec." edition = "2021" @@ -9,10 +9,9 @@ repository = "https://github.com/martin-kolarik/futures-signals-ext" homepage = "https://github.com/martin-kolarik/futures-signals-ext" [features] -default = ["option", "spawn-local"] +default = ["option", "spawn"] option = [] spawn = [] -spawn-local = [] [dependencies] artwrap = { version = "^0.1" } diff --git a/src/lib.rs b/src/lib.rs index ec8510f..6d4a1bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ #![feature(let_chains)] -#[cfg(any(feature = "spawn", feature = "spawn-local"))] +#[cfg(feature = "spawn")] mod spawn; -#[cfg(any(feature = "spawn", feature = "spawn-local"))] +#[cfg(feature = "spawn")] pub use spawn::*; mod entry; @@ -15,6 +15,3 @@ pub use ext::*; mod option; #[cfg(feature = "option")] pub use option::*; - -#[cfg(all(target_arch = "wasm32", feature = "spawn"))] -compile_error!("'spawn' feature is not available for 'wasm32'"); diff --git a/src/spawn.rs b/src/spawn.rs index 6c32de9..1e015aa 100644 --- a/src/spawn.rs +++ b/src/spawn.rs @@ -3,40 +3,40 @@ use std::future::Future; use futures_signals::signal_vec::VecDiff; pub trait SignalSpawn { - #[cfg(feature = "spawn")] + #[cfg(not(target_os = "unknown"))] fn spawn(self, f: F) where Self: Send, F: Fn(A) + Send + 'static; - #[cfg(feature = "spawn")] + #[cfg(not(target_os = "unknown"))] fn spawn_fut(self, f: F) where Self: Send, F: Fn(A) -> W + Send + 'static, W: Future + Send + 'static; - #[cfg(feature = "spawn-local")] - fn spawn_local(self, f: F) + #[cfg(all(target_arch = "wasm32"))] + fn spawn(self, f: F) where F: Fn(A) + 'static; - #[cfg(feature = "spawn-local")] - fn spawn_local_fut(self, f: F) + #[cfg(all(target_arch = "wasm32"))] + fn spawn_fut(self, f: F) where F: Fn(A) -> W + 'static, W: Future + 'static; } pub trait SignalVecSpawn { - #[cfg(feature = "spawn")] + #[cfg(not(target_os = "unknown"))] fn spawn(self, f: F) where Self: Send, F: Fn(VecDiff) + Send + 'static; - #[cfg(feature = "spawn-local")] - fn spawn_local(self, f: F) + #[cfg(all(target_arch = "wasm32"))] + fn spawn(self, f: F) where F: Fn(VecDiff) + 'static; } @@ -56,7 +56,6 @@ mod os { where S: Signal + 'static, { - #[cfg(feature = "spawn")] fn spawn(self, f: F) where Self: Send, @@ -68,7 +67,6 @@ mod os { }); } - #[cfg(feature = "spawn")] fn spawn_fut(self, f: F) where Self: Send, @@ -77,33 +75,12 @@ mod os { { artwrap::spawn(self.for_each(move |new| f(new))); } - - #[cfg(feature = "spawn-local")] - fn spawn_local(self, f: F) - where - F: Fn(A) + 'static, - { - self.spawn_local_fut(move |new| { - f(new); - ready(()) - }); - } - - #[cfg(feature = "spawn-local")] - fn spawn_local_fut(self, f: F) - where - F: Fn(A) -> W + 'static, - W: Future + 'static, - { - artwrap::spawn_local(self.for_each(move |new| f(new))); - } } impl SignalVecSpawn for S where S: SignalVec + 'static, { - #[cfg(feature = "spawn")] fn spawn(self, f: F) where Self: Send, @@ -114,21 +91,10 @@ mod os { ready(()) })); } - - #[cfg(feature = "spawn-local")] - fn spawn_local(self, f: F) - where - F: Fn(VecDiff) + 'static, - { - artwrap::spawn_local(self.for_each(move |new| { - f(new); - ready(()) - })); - } } } -#[cfg(all(target_arch = "wasm32", feature = "spawn-local"))] +#[cfg(all(target_arch = "wasm32"))] mod wasm { use std::future::{ready, Future}; @@ -143,43 +109,22 @@ mod wasm { where S: Signal + 'static, { - #[cfg(feature = "spawn")] - fn spawn(self, _: F) - where - Self: Send, - F: Fn(A) + Send + 'static, - { - unimplemented!() - } - - #[cfg(feature = "spawn")] - fn spawn_fut(self, f: F) - where - Self: Send, - F: Fn(A) -> W + Send + 'static, - W: Future + Send + 'static, - { - unimplemented!() - } - - #[cfg(feature = "spawn-local")] - fn spawn_local(self, f: F) + fn spawn(self, f: F) where F: Fn(A) + 'static, { - self.spawn_local_fut(move |new| { + self.spawn_fut(move |new| { f(new); ready(()) }); } - #[cfg(feature = "spawn-local")] - fn spawn_local_fut(self, f: F) + fn spawn_fut(self, f: F) where F: Fn(A) -> W + 'static, W: Future + 'static, { - artwrap::spawn_local(self.for_each(move |new| f(new))); + artwrap::spawn(self.for_each(move |new| f(new))); } } @@ -187,21 +132,11 @@ mod wasm { where S: SignalVec + 'static, { - #[cfg(feature = "spawn")] - fn spawn(self, _: F) - where - Self: Send, - F: Fn(VecDiff) + Send + 'static, - { - unimplemented!() - } - - #[cfg(feature = "spawn-local")] - fn spawn_local(self, f: F) + fn spawn(self, f: F) where F: Fn(VecDiff) + 'static, { - artwrap::spawn_local(self.for_each(move |new| { + artwrap::spawn(self.for_each(move |new| { f(new); ready(()) }));