Skip to content

Commit

Permalink
Revert "Add Send bound for JoinHandle::Output"
Browse files Browse the repository at this point in the history
This reverts commit 7ed7ceb.
  • Loading branch information
al8n committed Mar 26, 2024
1 parent 7ed7ceb commit d426923
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 56 deletions.
2 changes: 1 addition & 1 deletion lite/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "agnostic-lite"
version = "0.3.13"
version = "0.3.12"
edition.workspace = true
license.workspace = true
rust-version.workspace = true
Expand Down
9 changes: 0 additions & 9 deletions lite/src/async_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,9 @@ impl AsyncSpawner for AsyncStdSpawner {
where
F::Output: Send + 'static,
F: core::future::Future + Send + 'static,
<<Self as AsyncSpawner>::JoinHandle<F> as Future>::Output: Send,
{
::async_std::task::spawn(future)
}

fn spawn_detach<F>(future: F)
where
F::Output: Send + 'static,
F: Future + Send + 'static,
{
drop(::async_std::task::spawn(future));
}
}

impl AsyncLocalSpawner for AsyncStdSpawner {
Expand Down
25 changes: 3 additions & 22 deletions lite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ pub trait RuntimeLite: Sized + Unpin + Copy + Send + Sync + 'static {
where
F::Output: Send + 'static,
F: Future + Send + 'static,
<<Self::Spawner as AsyncSpawner>::JoinHandle<F> as Future>::Output: Send,
{
<Self::Spawner as AsyncSpawner>::spawn(future)
}
Expand Down Expand Up @@ -384,21 +383,13 @@ pub trait RuntimeLite: Sized + Unpin + Copy + Send + Sync + 'static {
#[cfg(any(test, feature = "test"))]
#[cfg_attr(docsrs, doc(cfg(any(test, feature = "test"))))]
pub mod tests {
#[cfg(feature = "time")]
use std::{
sync::{
atomic::{AtomicUsize, Ordering},
Arc,
},
time::Duration,
};
use core::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::time::Duration;

#[cfg(feature = "time")]
use super::{AfterHandle, RuntimeLite};

/// Unit test for the [`RuntimeLite::spawn_after`] function
#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
pub async fn spawn_after_unittest<R: RuntimeLite>() {
let ctr = Arc::new(AtomicUsize::new(1));
let ctr1 = ctr.clone();
Expand All @@ -416,8 +407,6 @@ pub mod tests {
/// Unit test for the [`RuntimeLite::spawn_after`] function
///
/// The task will be canceled before it completes
#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
pub async fn spawn_after_cancel_unittest<R: RuntimeLite>() {
let ctr = Arc::new(AtomicUsize::new(1));
let ctr1 = ctr.clone();
Expand All @@ -436,8 +425,6 @@ pub mod tests {
/// Unit test for the [`RuntimeLite::spawn_after`] function
///
/// The [`AfterHandle`] will be dropped immediately after it is created
#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
pub async fn spawn_after_drop_unittest<R: RuntimeLite>() {
let ctr = Arc::new(AtomicUsize::new(1));
let ctr1 = ctr.clone();
Expand All @@ -455,8 +442,6 @@ pub mod tests {
/// Unit test for the [`RuntimeLite::spawn_after`] function
///
/// The [`AfterHandle`] will be abort after it is created, and the task will not be executed.
#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
pub async fn spawn_after_abort_unittest<R: RuntimeLite>() {
let ctr = Arc::new(AtomicUsize::new(1));
let ctr1 = ctr.clone();
Expand All @@ -475,8 +460,6 @@ pub mod tests {
/// Unit test for the [`RuntimeLite::spawn_after`] function
///
/// The [`AfterHandle`] will be reset to passed than the original duration after it is created, and the task will be executed after the reset duration.
#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
pub async fn spawn_after_reset_to_pass_unittest<R: RuntimeLite>() {
let ctr = Arc::new(AtomicUsize::new(1));
let ctr1 = ctr.clone();
Expand All @@ -495,8 +478,6 @@ pub mod tests {
/// Unit test for the [`RuntimeLite::spawn_after`] function
///
/// The [`AfterHandle`] will be reset to future than the original duration after it is created, and the task will be executed after the reset duration.
#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
pub async fn spawn_after_reset_to_future_unittest<R: RuntimeLite>() {
let ctr = Arc::new(AtomicUsize::new(1));
let ctr1 = ctr.clone();
Expand Down
3 changes: 1 addition & 2 deletions lite/src/smol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ impl AsyncSpawner for SmolSpawner {
fn spawn<F>(future: F) -> Self::JoinHandle<F::Output>
where
F::Output: Send + 'static,
F: Future + Send + 'static,
<<Self as AsyncSpawner>::JoinHandle<F> as Future>::Output: Send,
F: core::future::Future + Send + 'static,
{
::smol::spawn(future)
}
Expand Down
10 changes: 6 additions & 4 deletions lite/src/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ pub trait AsyncSpawner: Copy + Send + Sync + 'static {
fn spawn<F>(future: F) -> Self::JoinHandle<F::Output>
where
F::Output: Send + 'static,
F: Future + Send + 'static,
<<Self as AsyncSpawner>::JoinHandle<F> as Future>::Output: Send;
F: Future + Send + 'static;

/// Spawn a future and detach it.
fn spawn_detach<F>(future: F)
where
F::Output: Send + 'static,
F: Future + Send + 'static;
F: Future + Send + 'static,
{
core::mem::drop(Self::spawn(future));
}
}

/// A spawner trait for spawning futures.
Expand Down Expand Up @@ -58,7 +60,7 @@ pub trait AsyncLocalSpawner: Copy + 'static {
/// A spawner trait for spawning blocking.
pub trait AsyncBlockingSpawner: Copy + 'static {
/// The join handle type for blocking tasks
type JoinHandle<R>: Detach + Send
type JoinHandle<R>: Detach
where
R: Send + 'static;

Expand Down
9 changes: 0 additions & 9 deletions lite/src/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,9 @@ impl AsyncSpawner for TokioSpawner {
where
F::Output: Send + 'static,
F: core::future::Future + Send + 'static,
<<Self as AsyncSpawner>::JoinHandle<F> as Future>::Output: Send,
{
::tokio::task::spawn(future)
}

fn spawn_detach<F>(future: F)
where
F::Output: Send + 'static,
F: Future + Send + 'static,
{
drop(::tokio::task::spawn(future));
}
}

impl AsyncLocalSpawner for TokioSpawner {
Expand Down
9 changes: 0 additions & 9 deletions lite/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,9 @@ impl AsyncSpawner for WasmSpawner {
where
F::Output: Send + 'static,
F: core::future::Future + Send + 'static,
<<Self as AsyncSpawner>::JoinHandle<F> as Future>::Output: Send,
{
<Self as super::AsyncLocalSpawner>::spawn_local(future)
}

fn spawn_detach<F>(future: F)
where
F::Output: Send + 'static,
F: Future + Send + 'static,
{
<Self as super::AsyncLocalSpawner>::spawn_local_detach(future)
}
}

impl AsyncLocalSpawner for WasmSpawner {
Expand Down

0 comments on commit d426923

Please sign in to comment.