mark spawn_local unstable

master
dignifiedquire 5 years ago
parent 1a6d4f6a2f
commit 92532612b7

@ -477,7 +477,7 @@ unsafe fn initialize<R: futures_io::AsyncRead>(_reader: &R, buf: &mut [u8]) {
std::ptr::write_bytes(buf.as_mut_ptr(), 0, buf.len())
}
#[cfg(test)]
#[cfg(all(test, not(target_os = "unknown")))]
mod tests {
use crate::io;
use crate::prelude::*;

@ -61,7 +61,7 @@ impl Builder {
}
/// Spawns a task locally with the configured settings.
#[cfg(not(target_os = "unknown"))]
#[cfg(all(not(target_os = "unknown"), feature = "unstable"))]
pub fn local<F, T>(self, future: F) -> io::Result<JoinHandle<T>>
where
F: Future<Output = T> + 'static,
@ -76,7 +76,7 @@ impl Builder {
}
/// Spawns a task locally with the configured settings.
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", feature = "unstable"))]
pub fn local<F, T>(self, future: F) -> io::Result<JoinHandle<T>>
where
F: Future<Output = T> + 'static,
@ -96,6 +96,27 @@ impl Builder {
Ok(JoinHandle::new(receiver, task))
}
/// Spawns a task locally with the configured settings.
#[cfg(all(target_arch = "wasm32", not(feature = "unstable")))]
pub(crate) fn local<F, T>(self, future: F) -> io::Result<JoinHandle<T>>
where
F: Future<Output = T> + 'static,
T: 'static,
{
use futures_channel::oneshot::channel;
let (sender, receiver) = channel();
let wrapped = self.build(async move {
let res = future.await;
let _ = sender.send(res);
});
let task = wrapped.tag.task().clone();
wasm_bindgen_futures::spawn_local(wrapped);
Ok(JoinHandle::new(receiver, task))
}
/// Spawns a task with the configured settings, blocking on its execution.
#[cfg(not(target_os = "unknown"))]
pub fn blocking<F, T>(self, future: F) -> T

@ -140,7 +140,6 @@ cfg_default! {
pub use sleep::sleep;
#[cfg(not(target_os = "unknown"))]
pub use spawn::spawn;
pub use spawn_local::spawn_local;
pub use task_local::{AccessError, LocalKey};
pub(crate) use task_local::LocalsMap;
@ -155,7 +154,6 @@ cfg_default! {
mod spawn;
#[cfg(not(target_os = "unknown"))]
mod spawn_blocking;
mod spawn_local;
mod task;
mod task_id;
mod task_local;
@ -168,3 +166,9 @@ cfg_default! {
#[cfg(not(any(feature = "unstable", test)))]
pub(crate) use spawn_blocking::spawn_blocking;
}
cfg_unstable! {
pub use spawn_local::spawn_local;
mod spawn_local;
}

Loading…
Cancel
Save