Skip to content

Commit

Permalink
Async code linked to artwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-kolarik committed Feb 29, 2024
1 parent f99cacc commit 05ac447
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
11 changes: 3 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ homepage = "https://github.com/martin-kolarik/futures-signals-ext"
[features]
default = ["option", "spawn-local"]
option = []
spawn = ["async-global-executor"]
spawn-local = ["async-global-executor", "wasm-bindgen-futures"]
spawn = []
spawn-local = []

[dependencies]
artwrap = { git = "https://github.com/martin-kolarik/artwrap.git" }
futures-signals = { version = "^0.3", default-features = false }
pin-project-lite = { version = "^0.2" }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
async-global-executor = { version = "^2.4", default-features = false, optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = { version = "^0.4", optional = true }
22 changes: 8 additions & 14 deletions src/futures_signals_spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ mod os {
F: Fn(A) -> W + Send + 'static,
W: Future<Output = ()> + Send + 'static,
{
async_global_executor::init();
async_global_executor::spawn(self.for_each(move |new| f(new))).detach();
artwrap::spawn(self.for_each(move |new| f(new)));
}

#[cfg(feature = "spawn-local")]
Expand All @@ -96,8 +95,7 @@ mod os {
F: Fn(A) -> W + 'static,
W: Future<Output = ()> + 'static,
{
async_global_executor::init();
async_global_executor::spawn_local(self.for_each(move |new| f(new))).detach();
artwrap::spawn_local(self.for_each(move |new| f(new)));
}
}

Expand All @@ -111,25 +109,21 @@ mod os {
Self: Send,
F: Fn(VecDiff<A>) + Send + 'static,
{
async_global_executor::init();
async_global_executor::spawn(self.for_each(move |new| {
artwrap::spawn(self.for_each(move |new| {
f(new);
ready(())
}))
.detach();
}));
}

#[cfg(feature = "spawn-local")]
fn spawn_local<F>(self, f: F)
where
F: Fn(VecDiff<A>) + 'static,
{
async_global_executor::init();
async_global_executor::spawn_local(self.for_each(move |new| {
artwrap::spawn_local(self.for_each(move |new| {
f(new);
ready(())
}))
.detach();
}));
}
}
}
Expand Down Expand Up @@ -185,7 +179,7 @@ mod wasm {
F: Fn(A) -> W + 'static,
W: Future<Output = ()> + 'static,
{
wasm_bindgen_futures::spawn_local(self.for_each(move |new| f(new)));
artwrap::spawn_local(self.for_each(move |new| f(new)));
}
}

Expand All @@ -207,7 +201,7 @@ mod wasm {
where
F: Fn(VecDiff<A>) + 'static,
{
wasm_bindgen_futures::spawn_local(self.for_each(move |new| {
artwrap::spawn_local(self.for_each(move |new| {
f(new);
ready(())
}));
Expand Down

0 comments on commit 05ac447

Please sign in to comment.