Skip to content

Commit 186cbb1

Browse files
mark spawn_local unstable
1 parent 006f6c6 commit 186cbb1

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

Diff for: src/io/read/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ unsafe fn initialize<R: futures_io::AsyncRead>(_reader: &R, buf: &mut [u8]) {
477477
std::ptr::write_bytes(buf.as_mut_ptr(), 0, buf.len())
478478
}
479479

480-
#[cfg(test)]
480+
#[cfg(all(test, not(target_os = "unknown")))]
481481
mod tests {
482482
use crate::io;
483483
use crate::prelude::*;

Diff for: src/task/builder.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Builder {
6161
}
6262

6363
/// Spawns a task locally with the configured settings.
64-
#[cfg(not(target_os = "unknown"))]
64+
#[cfg(all(not(target_os = "unknown"), feature = "unstable"))]
6565
pub fn local<F, T>(self, future: F) -> io::Result<JoinHandle<T>>
6666
where
6767
F: Future<Output = T> + 'static,
@@ -76,7 +76,7 @@ impl Builder {
7676
}
7777

7878
/// Spawns a task locally with the configured settings.
79-
#[cfg(target_arch = "wasm32")]
79+
#[cfg(all(target_arch = "wasm32", feature = "unstable"))]
8080
pub fn local<F, T>(self, future: F) -> io::Result<JoinHandle<T>>
8181
where
8282
F: Future<Output = T> + 'static,
@@ -96,6 +96,27 @@ impl Builder {
9696
Ok(JoinHandle::new(receiver, task))
9797
}
9898

99+
/// Spawns a task locally with the configured settings.
100+
#[cfg(all(target_arch = "wasm32", not(feature = "unstable")))]
101+
pub(crate) fn local<F, T>(self, future: F) -> io::Result<JoinHandle<T>>
102+
where
103+
F: Future<Output = T> + 'static,
104+
T: 'static,
105+
{
106+
use futures_channel::oneshot::channel;
107+
let (sender, receiver) = channel();
108+
109+
let wrapped = self.build(async move {
110+
let res = future.await;
111+
let _ = sender.send(res);
112+
});
113+
114+
let task = wrapped.tag.task().clone();
115+
wasm_bindgen_futures::spawn_local(wrapped);
116+
117+
Ok(JoinHandle::new(receiver, task))
118+
}
119+
99120
/// Spawns a task with the configured settings, blocking on its execution.
100121
#[cfg(not(target_os = "unknown"))]
101122
pub fn blocking<F, T>(self, future: F) -> T

Diff for: src/task/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ cfg_default! {
140140
pub use sleep::sleep;
141141
#[cfg(not(target_os = "unknown"))]
142142
pub use spawn::spawn;
143-
pub use spawn_local::spawn_local;
144143
pub use task_local::{AccessError, LocalKey};
145144

146145
pub(crate) use task_local::LocalsMap;
@@ -155,7 +154,6 @@ cfg_default! {
155154
mod spawn;
156155
#[cfg(not(target_os = "unknown"))]
157156
mod spawn_blocking;
158-
mod spawn_local;
159157
mod task;
160158
mod task_id;
161159
mod task_local;
@@ -168,3 +166,9 @@ cfg_default! {
168166
#[cfg(not(any(feature = "unstable", test)))]
169167
pub(crate) use spawn_blocking::spawn_blocking;
170168
}
169+
170+
cfg_unstable! {
171+
pub use spawn_local::spawn_local;
172+
173+
mod spawn_local;
174+
}

0 commit comments

Comments
 (0)