Skip to content

Commit

Permalink
Rectification of wrongly designed API, spawn_local removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-kolarik committed Sep 13, 2024
1 parent 55ff370 commit b90959b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 89 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "futures-signals-ext"
version = "0.2.0"
version = "0.3.0"
authors = ["[email protected]"]
description = "Extension to futures-signals: MutableOption with combinators, spawning, predicate driven selections from SignalVec."
edition = "2021"
Expand All @@ -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" }
Expand Down
7 changes: 2 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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'");
97 changes: 16 additions & 81 deletions src/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@ use std::future::Future;
use futures_signals::signal_vec::VecDiff;

pub trait SignalSpawn<A> {
#[cfg(feature = "spawn")]
#[cfg(not(target_os = "unknown"))]
fn spawn<F>(self, f: F)
where
Self: Send,
F: Fn(A) + Send + 'static;

#[cfg(feature = "spawn")]
#[cfg(not(target_os = "unknown"))]
fn spawn_fut<F, W>(self, f: F)
where
Self: Send,
F: Fn(A) -> W + Send + 'static,
W: Future<Output = ()> + Send + 'static;

#[cfg(feature = "spawn-local")]
fn spawn_local<F>(self, f: F)
#[cfg(all(target_arch = "wasm32"))]
fn spawn<F>(self, f: F)
where
F: Fn(A) + 'static;

#[cfg(feature = "spawn-local")]
fn spawn_local_fut<F, W>(self, f: F)
#[cfg(all(target_arch = "wasm32"))]
fn spawn_fut<F, W>(self, f: F)
where
F: Fn(A) -> W + 'static,
W: Future<Output = ()> + 'static;
}

pub trait SignalVecSpawn<A> {
#[cfg(feature = "spawn")]
#[cfg(not(target_os = "unknown"))]
fn spawn<F>(self, f: F)
where
Self: Send,
F: Fn(VecDiff<A>) + Send + 'static;

#[cfg(feature = "spawn-local")]
fn spawn_local<F>(self, f: F)
#[cfg(all(target_arch = "wasm32"))]
fn spawn<F>(self, f: F)
where
F: Fn(VecDiff<A>) + 'static;
}
Expand All @@ -56,7 +56,6 @@ mod os {
where
S: Signal<Item = A> + 'static,
{
#[cfg(feature = "spawn")]
fn spawn<F>(self, f: F)
where
Self: Send,
Expand All @@ -68,7 +67,6 @@ mod os {
});
}

#[cfg(feature = "spawn")]
fn spawn_fut<F, W>(self, f: F)
where
Self: Send,
Expand All @@ -77,33 +75,12 @@ mod os {
{
artwrap::spawn(self.for_each(move |new| f(new)));
}

#[cfg(feature = "spawn-local")]
fn spawn_local<F>(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<F, W>(self, f: F)
where
F: Fn(A) -> W + 'static,
W: Future<Output = ()> + 'static,
{
artwrap::spawn_local(self.for_each(move |new| f(new)));
}
}

impl<A, S> SignalVecSpawn<A> for S
where
S: SignalVec<Item = A> + 'static,
{
#[cfg(feature = "spawn")]
fn spawn<F>(self, f: F)
where
Self: Send,
Expand All @@ -114,21 +91,10 @@ mod os {
ready(())
}));
}

#[cfg(feature = "spawn-local")]
fn spawn_local<F>(self, f: F)
where
F: Fn(VecDiff<A>) + '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};

Expand All @@ -143,65 +109,34 @@ mod wasm {
where
S: Signal<Item = A> + 'static,
{
#[cfg(feature = "spawn")]
fn spawn<F>(self, _: F)
where
Self: Send,
F: Fn(A) + Send + 'static,
{
unimplemented!()
}

#[cfg(feature = "spawn")]
fn spawn_fut<F, W>(self, f: F)
where
Self: Send,
F: Fn(A) -> W + Send + 'static,
W: Future<Output = ()> + Send + 'static,
{
unimplemented!()
}

#[cfg(feature = "spawn-local")]
fn spawn_local<F>(self, f: F)
fn spawn<F>(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<F, W>(self, f: F)
fn spawn_fut<F, W>(self, f: F)
where
F: Fn(A) -> W + 'static,
W: Future<Output = ()> + 'static,
{
artwrap::spawn_local(self.for_each(move |new| f(new)));
artwrap::spawn(self.for_each(move |new| f(new)));
}
}

impl<A, S> SignalVecSpawn<A> for S
where
S: SignalVec<Item = A> + 'static,
{
#[cfg(feature = "spawn")]
fn spawn<F>(self, _: F)
where
Self: Send,
F: Fn(VecDiff<A>) + Send + 'static,
{
unimplemented!()
}

#[cfg(feature = "spawn-local")]
fn spawn_local<F>(self, f: F)
fn spawn<F>(self, f: F)
where
F: Fn(VecDiff<A>) + 'static,
{
artwrap::spawn_local(self.for_each(move |new| {
artwrap::spawn(self.for_each(move |new| {
f(new);
ready(())
}));
Expand Down

0 comments on commit b90959b

Please sign in to comment.