aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStjepan Glavina <stjepang@gmail.com>2020-09-18 16:20:17 +0200
committerStjepan Glavina <stjepang@gmail.com>2020-09-18 16:20:17 +0200
commit58259c207730e46c247977a0fd7cdadec5a4d8ae (patch)
tree7b4b4549b916e5210ad7efca07896d2f690492c0
parent2c42950de5b39fdd371d0baaef798138a391626a (diff)
downloadasync-task-58259c207730e46c247977a0fd7cdadec5a4d8ae.tar.gz
Rename Task to Runnable
-rw-r--r--benches/spawn.rs8
-rw-r--r--examples/spawn-local.rs8
-rw-r--r--examples/spawn-on-thread.rs8
-rw-r--r--examples/spawn.rs14
-rw-r--r--src/lib.rs41
-rw-r--r--src/raw.rs14
-rw-r--r--src/runnable.rs (renamed from src/task.rs)89
-rw-r--r--src/state.rs10
-rw-r--r--tests/basic.rs72
-rw-r--r--tests/cancel.rs18
-rw-r--r--tests/join.rs54
-rw-r--r--tests/panic.rs28
-rw-r--r--tests/ready.rs20
-rw-r--r--tests/waker_panic.rs46
-rw-r--r--tests/waker_pending.rs50
-rw-r--r--tests/waker_ready.rs38
16 files changed, 248 insertions, 270 deletions
diff --git a/benches/spawn.rs b/benches/spawn.rs
index e9f93ce..9d74110 100644
--- a/benches/spawn.rs
+++ b/benches/spawn.rs
@@ -17,8 +17,8 @@ fn task_create(b: &mut Bencher) {
#[bench]
fn task_run(b: &mut Bencher) {
b.iter(|| {
- let (task, handle) = async_task::spawn(async {}, drop);
- task.run();
+ let (runnable, handle) = async_task::spawn(async {}, drop);
+ runnable.run();
executor::block_on(handle).unwrap();
});
}
@@ -35,9 +35,9 @@ fn oneshot_create(b: &mut Bencher) {
fn oneshot_run(b: &mut Bencher) {
b.iter(|| {
let (tx, rx) = oneshot::channel::<()>();
- let task = Box::new(async move { tx.send(()).map_err(|_| ()) });
+ let runnable = Box::new(async move { tx.send(()).map_err(|_| ()) });
- let future = task.and_then(|_| rx.map_err(|_| ()));
+ let future = runnable.and_then(|_| rx.map_err(|_| ()));
executor::block_on(future).unwrap();
});
}
diff --git a/examples/spawn-local.rs b/examples/spawn-local.rs
index 1e1180c..2693aec 100644
--- a/examples/spawn-local.rs
+++ b/examples/spawn-local.rs
@@ -4,11 +4,11 @@ use std::cell::Cell;
use std::future::Future;
use std::rc::Rc;
-use async_task::{JoinHandle, Task};
+use async_task::{JoinHandle, Runnable};
thread_local! {
// A channel that holds scheduled tasks.
- static QUEUE: (flume::Sender<Task>, flume::Receiver<Task>) = flume::unbounded();
+ static QUEUE: (flume::Sender<Runnable>, flume::Receiver<Runnable>) = flume::unbounded();
}
/// Spawns a future on the executor.
@@ -19,10 +19,10 @@ where
{
// Create a task that is scheduled by sending itself into the channel.
let schedule = |t| QUEUE.with(|(s, _)| s.send(t).unwrap());
- let (task, handle) = async_task::spawn_local(future, schedule);
+ let (runnable, handle) = async_task::spawn_local(future, schedule);
// Schedule the task by sending it into the queue.
- task.schedule();
+ runnable.schedule();
handle
}
diff --git a/examples/spawn-on-thread.rs b/examples/spawn-on-thread.rs
index 3b7e522..a3da7be 100644
--- a/examples/spawn-on-thread.rs
+++ b/examples/spawn-on-thread.rs
@@ -29,16 +29,16 @@ where
// Create a task that is scheduled by sending itself into the channel.
let schedule = move |t| s.upgrade().unwrap().send(t).unwrap();
- let (task, handle) = async_task::spawn(future, schedule);
+ let (runnable, handle) = async_task::spawn(future, schedule);
// Schedule the task by sending it into the channel.
- task.schedule();
+ runnable.schedule();
// Spawn a thread running the task to completion.
thread::spawn(move || {
// Keep taking the task from the channel and running it until completion.
- for task in receiver {
- task.run();
+ for runnable in receiver {
+ runnable.run();
}
});
diff --git a/examples/spawn.rs b/examples/spawn.rs
index 63e84b6..07d6acd 100644
--- a/examples/spawn.rs
+++ b/examples/spawn.rs
@@ -4,7 +4,7 @@ use std::future::Future;
use std::panic::catch_unwind;
use std::thread;
-use async_task::{JoinHandle, Task};
+use async_task::{JoinHandle, Runnable};
use futures_lite::future;
use once_cell::sync::Lazy;
@@ -15,14 +15,14 @@ where
T: Send + 'static,
{
// A channel that holds scheduled tasks.
- static QUEUE: Lazy<flume::Sender<Task>> = Lazy::new(|| {
- let (sender, receiver) = flume::unbounded::<Task>();
+ static QUEUE: Lazy<flume::Sender<Runnable>> = Lazy::new(|| {
+ let (sender, receiver) = flume::unbounded::<Runnable>();
// Start the executor thread.
thread::spawn(|| {
- for task in receiver {
+ for runnable in receiver {
// Ignore panics for simplicity.
- let _ignore_panic = catch_unwind(|| task.run());
+ let _ignore_panic = catch_unwind(|| runnable.run());
}
});
@@ -31,10 +31,10 @@ where
// Create a task that is scheduled by sending itself into the channel.
let schedule = |t| QUEUE.send(t).unwrap();
- let (task, handle) = async_task::spawn(future, schedule);
+ let (runnable, handle) = async_task::spawn(future, schedule);
// Schedule the task by sending it into the channel.
- task.schedule();
+ runnable.schedule();
handle
}
diff --git a/src/lib.rs b/src/lib.rs
index 63ca99c..194a421 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -15,10 +15,10 @@
//! # let future = async { 1 + 2 };
//! #
//! # // A function that schedules the task when it gets woken up.
-//! # let schedule = move |task| sender.send(task).unwrap();
+//! # let schedule = move |runnable| sender.send(runnable).unwrap();
//! #
//! # // Construct a task.
-//! # let (task, handle) = async_task::spawn(future, schedule);
+//! # let (runnable, handle) = async_task::spawn(future, schedule);
//! ```
//!
//! A task is constructed using either [`spawn`] or [`spawn_local`]:
@@ -30,16 +30,16 @@
//! let future = async { 1 + 2 };
//!
//! // A function that schedules the task when it gets woken up.
-//! let schedule = move |task| sender.send(task).unwrap();
+//! let schedule = move |runnable| sender.send(runnable).unwrap();
//!
//! // Construct a task.
-//! let (task, handle) = async_task::spawn(future, schedule);
+//! let (runnable, handle) = async_task::spawn(future, schedule);
//!
//! // Push the task into the queue by invoking its schedule function.
-//! task.schedule();
+//! runnable.schedule();
//! ```
//!
-//! The function returns a runnable [`Task`] and a [`JoinHandle`] that can await the result.
+//! The function returns a runnable [`Runnable`] and a [`JoinHandle`] that can await the result.
//!
//! # Execution
//!
@@ -53,16 +53,16 @@
//! # let future = async { 1 + 2 };
//! #
//! # // A function that schedules the task when it gets woken up.
-//! # let schedule = move |task| sender.send(task).unwrap();
+//! # let schedule = move |runnable| sender.send(runnable).unwrap();
//! #
//! # // Construct a task.
-//! # let (task, handle) = async_task::spawn(future, schedule);
+//! # let (runnable, handle) = async_task::spawn(future, schedule);
//! #
//! # // Push the task into the queue by invoking its schedule function.
-//! # task.schedule();
+//! # runnable.schedule();
//! #
-//! for task in receiver {
-//! task.run();
+//! for runnable in receiver {
+//! runnable.run();
//! }
//! ```
//!
@@ -72,10 +72,10 @@
//!
//! # Cancellation
//!
-//! Both [`Task`] and [`JoinHandle`] have methods that cancel the task. When canceled, the task's
-//! future will not be polled again and will get dropped instead.
+//! Both [`Runnable`] and [`JoinHandle`] have methods that cancel the task. When canceled, the
+//! task's future will not be polled again and will get dropped instead.
//!
-//! If canceled by the [`Task`] instance, the task is destroyed immediately. If canceled by the
+//! If canceled by the [`Runnable`] instance, the task is destroyed immediately. If canceled by the
//! [`JoinHandle`] instance, it will be scheduled one more time and the next attempt to run it will
//! simply destroy it.
//!
@@ -90,12 +90,7 @@
//! The layout of a task is equivalent to 4 `usize`s followed by the schedule function, and then by
//! a union of the future and its output.
//!
-//! [`spawn`]: fn.spawn.html
-//! [`spawn_local`]: fn.spawn_local.html
-//! [`Task`]: struct.Task.html
-//! [`JoinHandle`]: struct.JoinHandle.html
-//! [`Waker`]: https://doc.rust-lang.org/std/task/struct.Waker.html
-//! [`block_on`]: https://github.com/async-rs/async-task/blob/master/examples/block.rs
+//! [`block_on`]: https://github.com/stjepang/async-task/blob/master/examples/block.rs
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
@@ -108,11 +103,11 @@ mod header;
mod join_handle;
mod raw;
mod state;
-mod task;
+mod runnable;
mod utils;
pub use crate::join_handle::JoinHandle;
-pub use crate::task::{spawn, Task};
+pub use crate::runnable::{spawn, Runnable};
#[cfg(feature = "std")]
-pub use crate::task::spawn_local;
+pub use crate::runnable::spawn_local;
diff --git a/src/raw.rs b/src/raw.rs
index 7144aca..51dddd7 100644
--- a/src/raw.rs
+++ b/src/raw.rs
@@ -10,7 +10,7 @@ use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
use crate::header::Header;
use crate::state::*;
use crate::utils::{abort, abort_on_panic, extend};
-use crate::Task;
+use crate::Runnable;
/// The vtable for a task.
pub(crate) struct TaskVTable {
@@ -83,7 +83,7 @@ impl<F, T, S> Clone for RawTask<F, T, S> {
impl<F, T, S> RawTask<F, T, S>
where
F: Future<Output = T> + 'static,
- S: Fn(Task) + Send + Sync + 'static,
+ S: Fn(Runnable) + Send + Sync + 'static,
{
const RAW_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(
Self::clone_waker,
@@ -94,7 +94,7 @@ where
/// Allocates a task with the given `future` and `schedule` function.
///
- /// It is assumed that initially only the `Task` reference and the `JoinHandle` exist.
+ /// It is assumed that initially only the `Runnable` reference and the `JoinHandle` exist.
pub(crate) fn allocate(future: F, schedule: S) -> NonNull<()> {
// Compute the layout of the task for allocation. Abort if the computation fails.
let task_layout = abort_on_panic(|| Self::task_layout());
@@ -295,7 +295,7 @@ where
// Schedule the task. There is no need to call `Self::schedule(ptr)`
// because the schedule function cannot be destroyed while the waker is
// still alive.
- let task = Task {
+ let task = Runnable {
raw_task: NonNull::new_unchecked(ptr as *mut ()),
};
(*raw.schedule)(task);
@@ -386,7 +386,7 @@ where
_waker = Waker::from_raw(Self::clone_waker(ptr));
}
- let task = Task {
+ let task = Runnable {
raw_task: NonNull::new_unchecked(ptr as *mut ()),
};
(*raw.schedule)(task);
@@ -593,12 +593,12 @@ where
struct Guard<F, T, S>(RawTask<F, T, S>)
where
F: Future<Output = T> + 'static,
- S: Fn(Task) + Send + Sync + 'static;
+ S: Fn(Runnable) + Send + Sync + 'static;
impl<F, T, S> Drop for Guard<F, T, S>
where
F: Future<Output = T> + 'static,
- S: Fn(Task) + Send + Sync + 'static,
+ S: Fn(Runnable) + Send + Sync + 'static,
{
fn drop(&mut self) {
let raw = self.0;
diff --git a/src/task.rs b/src/runnable.rs
index 02ef126..12f9619 100644
--- a/src/task.rs
+++ b/src/runnable.rs
@@ -13,8 +13,8 @@ use crate::JoinHandle;
/// Creates a new task.
///
-/// This constructor returns a [`Task`] reference that runs the future and a [`JoinHandle`] that
-/// awaits its result.
+/// This constructor returns a [`Runnable`] reference that runs the future and a [`JoinHandle`]
+/// that awaits its result.
///
/// When run, the task polls `future`. When woken up, it gets scheduled for running by the
/// `schedule` function.
@@ -25,11 +25,6 @@ use crate::JoinHandle;
/// If you need to spawn a future that does not implement [`Send`], consider using the
/// [`spawn_local`] function instead.
///
-/// [`Task`]: struct.Task.html
-/// [`JoinHandle`]: struct.JoinHandle.html
-/// [`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
-/// [`spawn_local`]: fn.spawn_local.html
-///
/// # Examples
///
/// ```
@@ -40,16 +35,16 @@ use crate::JoinHandle;
///
/// // If the task gets woken up, it will be sent into this channel.
/// let (s, r) = flume::unbounded();
-/// let schedule = move |task| s.send(task).unwrap();
+/// let schedule = move |runnable| s.send(runnable).unwrap();
///
/// // Create a task with the future and the schedule function.
-/// let (task, handle) = async_task::spawn(future, schedule);
+/// let (runnable, handle) = async_task::spawn(future, schedule);
/// ```
-pub fn spawn<F, T, S>(future: F, schedule: S) -> (Task, JoinHandle<T>)
+pub fn spawn<F, T, S>(future: F, schedule: S) -> (Runnable, JoinHandle<T>)
where
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
- S: Fn(Task) + Send + Sync + 'static,
+ S: Fn(Runnable) + Send + Sync + 'static,
{
// Allocate large futures on the heap.
let raw_task = if mem::size_of::<F>() >= 2048 {
@@ -59,7 +54,7 @@ where
RawTask::<F, T, S>::allocate(future, schedule)
};
- let task = Task { raw_task };
+ let task = Runnable { raw_task };
let handle = JoinHandle {
raw_task,
_marker: PhantomData,
@@ -69,8 +64,8 @@ where
/// Creates a new local task.
///
-/// This constructor returns a [`Task`] reference that runs the future and a [`JoinHandle`] that
-/// awaits its result.
+/// This constructor returns a [`Runnable`] reference that runs the future and a [`JoinHandle`]
+/// that awaits its result.
///
/// When run, the task polls `future`. When woken up, it gets scheduled for running by the
/// `schedule` function.
@@ -79,16 +74,11 @@ where
/// push the task into some kind of queue so that it can be processed later.
///
/// Unlike [`spawn`], this function does not require the future to implement [`Send`]. If the
-/// [`Task`] reference is run or dropped on a thread it was not created on, a panic will occur.
+/// [`Runnable`] reference is run or dropped on a thread it was not created on, a panic will occur.
///
/// **NOTE:** This function is only available when the `std` feature for this crate is enabled (it
/// is by default).
///
-/// [`Task`]: struct.Task.html
-/// [`JoinHandle`]: struct.JoinHandle.html
-/// [`spawn`]: fn.spawn.html
-/// [`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
-///
/// # Examples
///
/// ```
@@ -99,17 +89,17 @@ where
///
/// // If the task gets woken up, it will be sent into this channel.
/// let (s, r) = flume::unbounded();
-/// let schedule = move |task| s.send(task).unwrap();
+/// let schedule = move |runnable| s.send(runnable).unwrap();
///
/// // Create a task with the future and the schedule function.
-/// let (task, handle) = async_task::spawn_local(future, schedule);
+/// let (runnable, handle) = async_task::spawn_local(future, schedule);
/// ```
#[cfg(feature = "std")]
-pub fn spawn_local<F, T, S>(future: F, schedule: S) -> (Task, JoinHandle<T>)
+pub fn spawn_local<F, T, S>(future: F, schedule: S) -> (Runnable, JoinHandle<T>)
where
F: Future<Output = T> + 'static,
T: 'static,
- S: Fn(Task) + Send + Sync + 'static,
+ S: Fn(Runnable) + Send + Sync + 'static,
{
use std::mem::ManuallyDrop;
use std::pin::Pin;
@@ -168,7 +158,7 @@ where
RawTask::<_, T, S>::allocate(future, schedule)
};
- let task = Task { raw_task };
+ let task = Runnable { raw_task };
let handle = JoinHandle {
raw_task,
_marker: PhantomData,
@@ -178,38 +168,34 @@ where
/// A task reference that runs its future.
///
-/// At any moment in time, there is at most one [`Task`] reference associated with a particular
-/// task. Running consumes the [`Task`] reference and polls its internal future. If the future is
-/// still pending after getting polled, the [`Task`] reference simply won't exist until a [`Waker`]
-/// notifies the task. If the future completes, its result becomes available to the [`JoinHandle`].
+/// At any moment in time, there is at most one [`Runnable`] reference associated with a particular
+/// task. Running consumes the [`Runnable`] reference and polls its internal future. If the future
+/// is still pending after getting polled, the [`Runnable`] reference simply won't exist until a
+/// [`Waker`] notifies the task. If the future completes, its result becomes available to the
+/// [`JoinHandle`].
///
-/// When a task is woken up, its [`Task`] reference is recreated and passed to the schedule
-/// function. In most executors, scheduling simply pushes the [`Task`] reference into a queue of
-/// runnable tasks.
+/// When a task is woken up, its [`Runnable`] reference is recreated and passed to the schedule
+/// function. In most executors, scheduling simply pushes the [`Runnable`] reference into a queue
+/// of runnable tasks.
///
-/// If the [`Task`] reference is dropped without getting run, the task is automatically canceled.
-/// When canceled, the task won't be scheduled again even if a [`Waker`] wakes it. It is possible
-/// for the [`JoinHandle`] to cancel while the [`Task`] reference exists, in which case an attempt
-/// to run the task won't do anything.
-///
-/// [`run()`]: struct.Task.html#method.run
-/// [`JoinHandle`]: struct.JoinHandle.html
-/// [`Task`]: struct.Task.html
-/// [`Waker`]: https://doc.rust-lang.org/std/task/struct.Waker.html
-pub struct Task {
+/// If the [`Runnable`] reference is dropped without getting run, the task is automatically
+/// canceled. When canceled, the task won't be scheduled again even if a [`Waker`] wakes it. It is
+/// possible for the [`JoinHandle`] to cancel while the [`Runnable`] reference exists, in which
+/// case an attempt to run the task won't do anything.
+pub struct Runnable {
/// A pointer to the heap-allocated task.
pub(crate) raw_task: NonNull<()>,
}
-unsafe impl Send for Task {}
-unsafe impl Sync for Task {}
+unsafe impl Send for Runnable {}
+unsafe impl Sync for Runnable {}
#[cfg(feature = "std")]
-impl std::panic::UnwindSafe for Task {}
+impl std::panic::UnwindSafe for Runnable {}
#[cfg(feature = "std")]
-impl std::panic::RefUnwindSafe for Task {}
+impl std::panic::RefUnwindSafe for Runnable {}
-impl Task {
+impl Runnable {
/// Schedules the task.
///
/// This is a convenience method that simply reschedules the task by passing it to its schedule
@@ -241,9 +227,6 @@ impl Task {
/// It is possible that polling the future panics, in which case the panic will be propagated
/// into the caller. It is advised that invocations of this method are wrapped inside
/// [`catch_unwind`]. If a panic occurs, the task is automatically canceled.
- ///
- /// [`JoinHandle`]: struct.JoinHandle.html
- /// [`catch_unwind`]: https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
pub fn run(self) -> bool {
let ptr = self.raw_task.as_ptr();
let header = ptr as *const Header;
@@ -264,7 +247,7 @@ impl Task {
}
}
-impl Drop for Task {
+impl Drop for Runnable {
fn drop(&mut self) {
let ptr = self.raw_task.as_ptr();
let header = ptr as *const Header;
@@ -290,12 +273,12 @@ impl Drop for Task {
}
}
-impl fmt::Debug for Task {
+impl fmt::Debug for Runnable {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let ptr = self.raw_task.as_ptr();
let header = ptr as *const Header;
- f.debug_struct("Task")
+ f.debug_struct("Runnable")
.field("header", unsafe { &(*header) })
.finish()
}
diff --git a/src/state.rs b/src/state.rs
index 099e6bc..343cc4d 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -1,7 +1,7 @@
/// Set if the task is scheduled for running.
///
-/// A task is considered to be scheduled whenever its `Task` reference exists. It therefore also
-/// begins in scheduled state at the moment of creation.
+/// A task is considered to be scheduled whenever its `Runnable` reference exists. It therefore
+/// also begins in scheduled state at the moment of creation.
///
/// This flag can't be set when the task is completed. However, it can be set while the task is
/// running, in which case it will be rescheduled as soon as polling finishes.
@@ -29,7 +29,7 @@ pub(crate) const COMPLETED: usize = 1 << 2;
/// If a task is closed, that means it's either canceled or its output has been consumed by the
/// `JoinHandle`. A task becomes closed when:
///
-/// 1. It gets canceled by `Task::cancel()`, `Task::drop()`, or `JoinHandle::cancel()`.
+/// 1. It gets canceled by `Runnable::drop()`, `Task::drop()`, or `Task::cancel()`.
/// 2. Its output gets awaited by the `JoinHandle`.
/// 3. It panics while polling the future.
/// 4. It is completed and the `JoinHandle` gets dropped.
@@ -38,7 +38,7 @@ pub(crate) const CLOSED: usize = 1 << 3;
/// Set if the `JoinHandle` still exists.
///
/// The `JoinHandle` is a special case in that it is only tracked by this flag, while all other
-/// task references (`Task` and `Waker`s) are tracked by the reference count.
+/// task references (`Runnable` and `Waker`s) are tracked by the reference count.
pub(crate) const HANDLE: usize = 1 << 4;
/// Set if the `JoinHandle` is awaiting the output.
@@ -65,6 +65,6 @@ pub(crate) const NOTIFYING: usize = 1 << 7;
/// bits contain the reference count. The value of `REFERENCE` represents a single reference in the
/// total reference count.
///
-/// Note that the reference counter only tracks the `Task` and `Waker`s. The `JoinHandle` is
+/// Note that the reference counter only tracks the `Runnable` and `Waker`s. The `JoinHandle` is
/// tracked separately by the `HANDLE` flag.
pub(crate) const REFERENCE: usize = 1 << 8;
diff --git a/tests/basic.rs b/tests/basic.rs
index 81311bf..b012b57 100644
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -3,7 +3,7 @@ use std::pin::Pin;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::task::{Context, Poll};
-use async_task::Task;
+use async_task::Runnable;
use futures_lite::future;
// Creates a future with event counters.
@@ -63,7 +63,7 @@ macro_rules! schedule {
}
let guard = Guard(Box::new(0));
- move |_task| {
+ move |_runnable| {
&guard;
$sched.fetch_add(1, Ordering::SeqCst);
}
@@ -79,14 +79,14 @@ fn try_await<T>(f: impl Future<Output = T>) -> Option<T> {
fn drop_and_detach() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
assert_eq!(POLL.load(Ordering::SeqCst), 0);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
assert_eq!(DROP_S.load(Ordering::SeqCst), 0);
- drop(task);
+ drop(runnable);
assert_eq!(POLL.load(Ordering::SeqCst), 0);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -103,7 +103,7 @@ fn drop_and_detach() {
fn detach_and_drop() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
handle.detach();
assert_eq!(POLL.load(Ordering::SeqCst), 0);
@@ -111,7 +111,7 @@ fn detach_and_drop() {
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
assert_eq!(DROP_S.load(Ordering::SeqCst), 0);
- drop(task);
+ drop(runnable);
assert_eq!(POLL.load(Ordering::SeqCst), 0);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -122,7 +122,7 @@ fn detach_and_drop() {
fn detach_and_run() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
handle.detach();
assert_eq!(POLL.load(Ordering::SeqCst), 0);
@@ -130,7 +130,7 @@ fn detach_and_run() {
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
assert_eq!(DROP_S.load(Ordering::SeqCst), 0);
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -141,9 +141,9 @@ fn detach_and_run() {
fn run_and_detach() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -160,7 +160,7 @@ fn run_and_detach() {
fn cancel_and_run() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
drop(handle);
assert_eq!(POLL.load(Ordering::SeqCst), 0);
@@ -168,7 +168,7 @@ fn cancel_and_run() {
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
assert_eq!(DROP_S.load(Ordering::SeqCst), 0);
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 0);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -179,9 +179,9 @@ fn cancel_and_run() {
fn run_and_cancel() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -198,7 +198,7 @@ fn run_and_cancel() {
fn cancel_join() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, mut handle) = async_task::spawn(f, s);
+ let (runnable, mut handle) = async_task::spawn(f, s);
assert!(try_await(&mut handle).is_none());
assert_eq!(POLL.load(Ordering::SeqCst), 0);
@@ -206,7 +206,7 @@ fn cancel_join() {
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
assert_eq!(DROP_S.load(Ordering::SeqCst), 0);
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -228,19 +228,19 @@ fn cancel_join() {
#[test]
fn schedule() {
let (s, r) = flume::unbounded();
- let schedule = move |t| s.send(t).unwrap();
- let (task, _handle) = async_task::spawn(future::poll_fn(|_| Poll::<()>::Pending), schedule);
+ let schedule = move |runnable| s.send(runnable).unwrap();
+ let (runnable, _handle) = async_task::spawn(future::poll_fn(|_| Poll::<()>::Pending), schedule);
assert!(r.is_empty());
- task.schedule();
+ runnable.schedule();
- let task = r.recv().unwrap();
+ let runnable = r.recv().unwrap();
assert!(r.is_empty());
- task.schedule();
+ runnable.schedule();
- let task = r.recv().unwrap();
+ let runnable = r.recv().unwrap();
assert!(r.is_empty());
- task.schedule();
+ runnable.schedule();
r.recv().unwrap();
}
@@ -250,12 +250,12 @@ fn schedule_counter() {
static COUNT: AtomicUsize = AtomicUsize::new(0);
let (s, r) = flume::unbounded();
- let schedule = move |t: Task| {
+ let schedule = move |runnable: Runnable| {
COUNT.fetch_add(1, Ordering::SeqCst);
- s.send(t).unwrap();
+ s.send(runnable).unwrap();
};
- let (task, _handle) = async_task::spawn(future::poll_fn(|_| Poll::<()>::Pending), schedule);
- task.schedule();
+ let (runnable, _handle) = async_task::spawn(future::poll_fn(|_| Poll::<()>::Pending), schedule);
+ runnable.schedule();
r.recv().unwrap().schedule();
r.recv().unwrap().schedule();
@@ -273,27 +273,27 @@ fn drop_inside_schedule() {
}
let guard = DropGuard(AtomicUsize::new(0));
- let (task, _) = async_task::spawn(async {}, move |task| {
+ let (runnable, _) = async_task::spawn(async {}, move |runnable| {
assert_eq!(guard.0.load(Ordering::SeqCst), 0);
- drop(task);
+ drop(runnable);
assert_eq!(guard.0.load(Ordering::SeqCst), 0);
});
- task.schedule();
+ runnable.schedule();
}
#[test]
fn waker() {
let (s, r) = flume::unbounded();
- let schedule = move |t| s.send(t).unwrap();
- let (task, _handle) = async_task::spawn(future::poll_fn(|_| Poll::<()>::Pending), schedule);
+ let schedule = move |runnable| s.send(runnable).unwrap();
+ let (runnable, _handle) = async_task::spawn(future::poll_fn(|_| Poll::<()>::Pending), schedule);
assert!(r.is_empty());
- let w = task.waker();
- task.run();
+ let w = runnable.waker();
+ runnable.run();
w.wake_by_ref();
- let task = r.recv().unwrap();
- task.run();
+ let runnable = r.recv().unwrap();
+ runnable.run();
w.wake();
r.recv().unwrap();
}
diff --git a/tests/cancel.rs b/tests/cancel.rs
index 3155876..4f6581a 100644
--- a/tests/cancel.rs
+++ b/tests/cancel.rs
@@ -5,7 +5,7 @@ use std::task::{Context, Poll};
use std::thread;
use std::time::Duration;
-use async_task::Task;
+use async_task::Runnable;
use easy_parallel::Parallel;
use futures_lite::future;
@@ -80,9 +80,9 @@ macro_rules! schedule {
}
let guard = Guard(Box::new(0));
- move |task: Task| {
+ move |runnable: Runnable| {
&guard;
- task.schedule();
+ runnable.schedule();
$sched.fetch_add(1, Ordering::SeqCst);
}
};
@@ -97,9 +97,9 @@ fn ms(ms: u64) -> Duration {
fn run_and_cancel() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -118,12 +118,12 @@ fn run_and_cancel() {
fn cancel_and_run() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
thread::sleep(ms(200));
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 0);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
@@ -149,11 +149,11 @@ fn cancel_and_run() {
fn cancel_during_run() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
- task.run();
+ runnable.run();
thread::sleep(ms(200));
diff --git a/tests/join.rs b/tests/join.rs
index 6a2505b..25bbf9a 100644
--- a/tests/join.rs
+++ b/tests/join.rs
@@ -7,7 +7,7 @@ use std::task::{Context, Poll};
use std::thread;
use std::time::Duration;
-use async_task::Task;
+use async_task::Runnable;
use easy_parallel::Parallel;
use futures_lite::future;
@@ -81,9 +81,9 @@ macro_rules! schedule {
}
let guard = Guard(Box::new(0));
- move |task: Task| {
+ move |runnable: Runnable| {
&guard;
- task.schedule();
+ runnable.schedule();
$sched.fetch_add(1, Ordering::SeqCst);
}
};
@@ -98,11 +98,11 @@ fn ms(ms: u64) -> Duration {
fn drop_and_join() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
assert_eq!(DROP_T.load(Ordering::SeqCst), 0);
- drop(task);
+ drop(runnable);
assert_eq!(DROP_T.load(Ordering::SeqCst), 0);
assert!(catch_unwind(|| future::block_on(handle)).is_err());
@@ -117,11 +117,11 @@ fn drop_and_join() {
fn run_and_join() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
assert_eq!(DROP_T.load(Ordering::SeqCst), 0);
- task.run();
+ runnable.run();
assert_eq!(DROP_T.load(Ordering::SeqCst), 0);
assert!(catch_unwind(|| future::block_on(handle)).is_ok());
@@ -136,14 +136,14 @@ fn run_and_join() {
fn detach_and_run() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
assert_eq!(DROP_T.load(Ordering::SeqCst), 0);
handle.detach();
assert_eq!(DROP_T.load(Ordering::SeqCst), 0);
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -155,11 +155,11 @@ fn detach_and_run() {
fn join_twice() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, mut handle) = async_task::spawn(f, s);
+ let (runnable, mut handle) = async_task::spawn(f, s);
assert_eq!(DROP_T.load(Ordering::SeqCst), 0);
- task.run();
+ runnable.run();
assert_eq!(DROP_T.load(Ordering::SeqCst), 0);
future::block_on(&mut handle);
@@ -184,12 +184,12 @@ fn join_twice() {
fn join_and_cancel() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
thread::sleep(ms(200));
- drop(task);
+ drop(runnable);
thread::sleep(ms(400));
assert_eq!(POLL.load(Ordering::SeqCst), 0);
@@ -215,13 +215,13 @@ fn join_and_cancel() {
fn join_and_run() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
thread::sleep(ms(400));
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -246,13 +246,13 @@ fn join_and_run() {
fn try_join_and_run_and_join() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, mut handle) = async_task::spawn(f, s);
+ let (runnable, mut handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
thread::sleep(ms(400));
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -284,13 +284,13 @@ fn try_join_and_run_and_join() {
fn try_join_and_cancel_and_run() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, mut handle) = async_task::spawn(f, s);
+ let (runnable, mut handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
thread::sleep(ms(200));
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 0);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -318,13 +318,13 @@ fn try_join_and_cancel_and_run() {
fn try_join_and_run_and_cancel() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, mut handle) = async_task::spawn(f, s);
+ let (runnable, mut handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
thread::sleep(ms(200));
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -369,18 +369,18 @@ fn await_output() {
}
for i in 0..10 {
- let (task, handle) = async_task::spawn(Fut::new(i), drop);
- task.run();
+ let (runnable, handle) = async_task::spawn(Fut::new(i), drop);
+ runnable.run();
assert_eq!(future::block_on(handle), i);
}
for i in 0..10 {
- let (task, handle) = async_task::spawn(Fut::new(vec![7; i]), drop);
- task.run();
+ let (runnable, handle) = async_task::spawn(Fut::new(vec![7; i]), drop);
+ runnable.run();
assert_eq!(future::block_on(handle), vec![7; i]);
}
- let (task, handle) = async_task::spawn(Fut::new("foo".to_string()), drop);
- task.run();
+ let (runnable, handle) = async_task::spawn(Fut::new("foo".to_string()), drop);
+ runnable.run();
assert_eq!(future::block_on(handle), "foo");
}
diff --git a/tests/panic.rs b/tests/panic.rs
index b14581d..8a25e2e 100644
--- a/tests/panic.rs
+++ b/tests/panic.rs
@@ -6,7 +6,7 @@ use std::task::{Context, Poll};
use std::thread;
use std::time::Duration;
-use async_task::Task;
+use async_task::Runnable;
use easy_parallel::Parallel;
use futures_lite::future;
@@ -68,7 +68,7 @@ macro_rules! schedule {
}
let guard = Guard(Box::new(0));
- move |_task: Task| {
+ move |_runnable: Runnable| {
&guard;
$sched.fetch_add(1, Ordering::SeqCst);
}
@@ -84,11 +84,11 @@ fn ms(ms: u64) -> Duration {
fn cancel_during_run() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
- assert!(catch_unwind(|| task.run()).is_err());
+ assert!(catch_unwind(|| runnable.run()).is_err());
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -110,9 +110,9 @@ fn cancel_during_run() {
fn run_and_join() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- assert!(catch_unwind(|| task.run()).is_err());
+ assert!(catch_unwind(|| runnable.run()).is_err());
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -129,7 +129,7 @@ fn run_and_join() {
fn try_join_and_run_and_join() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, mut handle) = async_task::spawn(f, s);
+ let (runnable, mut handle) = async_task::spawn(f, s);
future::block_on(future::or(&mut handle, future::ready(Default::default())));
assert_eq!(POLL.load(Ordering::SeqCst), 0);
@@ -137,7 +137,7 @@ fn try_join_and_run_and_join() {
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
assert_eq!(DROP_S.load(Ordering::SeqCst), 0);
- assert!(catch_unwind(|| task.run()).is_err());
+ assert!(catch_unwind(|| runnable.run()).is_err());
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -154,11 +154,11 @@ fn try_join_and_run_and_join() {
fn join_during_run() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
- assert!(catch_unwind(|| task.run()).is_err());
+ assert!(catch_unwind(|| runnable.run()).is_err());
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -184,11 +184,11 @@ fn join_during_run() {
fn try_join_during_run() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, mut handle) = async_task::spawn(f, s);
+ let (runnable, mut handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
- assert!(catch_unwind(|| task.run()).is_err());
+ assert!(catch_unwind(|| runnable.run()).is_err());
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -211,11 +211,11 @@ fn try_join_during_run() {
fn detach_during_run() {
future!(f, POLL, DROP_F);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
- assert!(catch_unwind(|| task.run()).is_err());
+ assert!(catch_unwind(|| runnable.run()).is_err());
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
diff --git a/tests/ready.rs b/tests/ready.rs
index 925f994..72a2b72 100644
--- a/tests/ready.rs
+++ b/tests/ready.rs
@@ -5,7 +5,7 @@ use std::task::{Context, Poll};
use std::thread;
use std::time::Duration;
-use async_task::Task;
+use async_task::Runnable;
use easy_parallel::Parallel;
use futures_lite::future;
@@ -80,7 +80,7 @@ macro_rules! schedule {
}
let guard = Guard(Box::new(0));
- move |_task: Task| {
+ move |_runnable: Runnable| {
&guard;
$sched.fetch_add(1, Ordering::SeqCst);
}
@@ -96,11 +96,11 @@ fn ms(ms: u64) -> Duration {
fn cancel_during_run() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -138,11 +138,11 @@ fn cancel_during_run() {
fn join_during_run() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -171,11 +171,11 @@ fn join_during_run() {
fn try_join_during_run() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, mut handle) = async_task::spawn(f, s);
+ let (runnable, mut handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -200,11 +200,11 @@ fn try_join_during_run() {
fn detach_during_run() {
future!(f, POLL, DROP_F, DROP_T);
schedule!(s, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
Parallel::new()
.add(|| {
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
diff --git a/tests/waker_panic.rs b/tests/waker_panic.rs
index 571f8c8..5ff43fd 100644
--- a/tests/waker_panic.rs
+++ b/tests/waker_panic.rs
@@ -7,7 +7,7 @@ use std::task::{Context, Poll};
use std::thread;
use std::time::Duration;
-use async_task::Task;
+use async_task::Runnable;
use atomic_waker::AtomicWaker;
use easy_parallel::Parallel;
use futures_lite::future;
@@ -85,10 +85,10 @@ macro_rules! schedule {
}
let guard = Guard(Box::new(0));
- let sched = move |task: Task| {
+ let sched = move |runnable: Runnable| {
&guard;
$sched.fetch_add(1, Ordering::SeqCst);
- s.send(task).unwrap();
+ s.send(runnable).unwrap();
};
(sched, r)
@@ -108,16 +108,16 @@ fn try_await<T>(f: impl Future<Output = T>) -> Option<T> {
fn wake_during_run() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
let w = waker();
w.wake_by_ref();
- let task = chan.recv().unwrap();
+ let runnable = chan.recv().unwrap();
Parallel::new()
.add(|| {
- assert!(catch_unwind(|| task.run()).is_err());
+ assert!(catch_unwind(|| runnable.run()).is_err());
drop(waker());
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
@@ -151,16 +151,16 @@ fn wake_during_run() {
fn cancel_during_run() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
let w = waker();
w.wake();
- let task = chan.recv().unwrap();
+ let runnable = chan.recv().unwrap();
Parallel::new()
.add(|| {
- assert!(catch_unwind(|| task.run()).is_err());
+ assert!(catch_unwind(|| runnable.run()).is_err());
drop(waker());
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
@@ -193,16 +193,16 @@ fn cancel_during_run() {
fn wake_and_cancel_during_run() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
let w = waker();
w.wake_by_ref();
- let task = chan.recv().unwrap();
+ let runnable = chan.recv().unwrap();
Parallel::new()
.add(|| {
- assert!(catch_unwind(|| task.run()).is_err());
+ assert!(catch_unwind(|| runnable.run()).is_err());
drop(waker());
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
@@ -242,16 +242,16 @@ fn wake_and_cancel_during_run() {
fn cancel_and_wake_during_run() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
let w = waker();
w.wake_by_ref();
- let task = chan.recv().unwrap();
+ let runnable = chan.recv().unwrap();
Parallel::new()
.add(|| {
- assert!(catch_unwind(|| task.run()).is_err());
+ assert!(catch_unwind(|| runnable.run()).is_err());
drop(waker());
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
@@ -291,9 +291,9 @@ fn cancel_and_wake_during_run() {
fn panic_and_poll() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
waker().wake();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
@@ -303,8 +303,8 @@ fn panic_and_poll() {
let mut handle = handle;
assert!(try_await(&mut handle).is_none());
- let task = chan.recv().unwrap();
- assert!(catch_unwind(|| task.run()).is_err());
+ let runnable = chan.recv().unwrap();
+ assert!(catch_unwind(|| runnable.run()).is_err());
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
diff --git a/tests/waker_pending.rs b/tests/waker_pending.rs
index 829d3aa..edbffde 100644
--- a/tests/waker_pending.rs
+++ b/tests/waker_pending.rs
@@ -5,7 +5,7 @@ use std::task::{Context, Poll};
use std::thread;
use std::time::Duration;
-use async_task::Task;
+use async_task::Runnable;
use atomic_waker::AtomicWaker;
use easy_parallel::Parallel;
@@ -76,10 +76,10 @@ macro_rules! schedule {
}
let guard = Guard(Box::new(0));
- let sched = move |task: Task| {
+ let sched = move |runnable: Runnable| {
&guard;
$sched.fetch_add(1, Ordering::SeqCst);
- s.send(task).unwrap();
+ s.send(runnable).unwrap();
};
(sched, r)
@@ -95,16 +95,16 @@ fn ms(ms: u64) -> Duration {
fn wake_during_run() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, _handle) = async_task::spawn(f, s);
+ let (runnable, _handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
let w = waker();
w.wake_by_ref();
- let task = chan.recv().unwrap();
+ let runnable = chan.recv().unwrap();
Parallel::new()
.add(|| {
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 2);
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
@@ -139,16 +139,16 @@ fn wake_during_run() {
fn cancel_during_run() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
let w = waker();
w.wake();
- let task = chan.recv().unwrap();
+ let runnable = chan.recv().unwrap();
Parallel::new()
.add(|| {
- task.run();
+ runnable.run();
drop(waker());
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
@@ -181,16 +181,16 @@ fn cancel_during_run() {
fn wake_and_cancel_during_run() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
let w = waker();
w.wake_by_ref();
- let task = chan.recv().unwrap();
+ let runnable = chan.recv().unwrap();
Parallel::new()
.add(|| {
- task.run();
+ runnable.run();
drop(waker());
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
@@ -230,16 +230,16 @@ fn wake_and_cancel_during_run() {
fn cancel_and_wake_during_run() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
let w = waker();
w.wake_by_ref();
- let task = chan.recv().unwrap();
+ let runnable = chan.recv().unwrap();
Parallel::new()
.add(|| {
- task.run();
+ runnable.run();
drop(waker());
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
@@ -279,9 +279,9 @@ fn cancel_and_wake_during_run() {
fn drop_last_waker() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
let w = waker();
handle.detach();
@@ -310,9 +310,9 @@ fn drop_last_waker() {
fn cancel_last_handle() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
drop(waker());
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
@@ -339,9 +339,9 @@ fn cancel_last_handle() {
fn drop_last_handle() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
- task.run();
+ runnable.run();
drop(waker());
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
diff --git a/tests/waker_ready.rs b/tests/waker_ready.rs
index e7e8103..6acad29 100644
--- a/tests/waker_ready.rs
+++ b/tests/waker_ready.rs
@@ -6,7 +6,7 @@ use std::task::{Context, Poll};
use std::thread;
use std::time::Duration;
-use async_task::Task;
+use async_task::Runnable;
use atomic_waker::AtomicWaker;
// Creates a future with event counters.
@@ -82,10 +82,10 @@ macro_rules! schedule {
}
let guard = Guard(Box::new(0));
- let sched = move |task: Task| {
+ let sched = move |runnable: Runnable| {
&guard;
$sched.fetch_add(1, Ordering::SeqCst);
- s.send(task).unwrap();
+ s.send(runnable).unwrap();
};
(sched, r)
@@ -101,12 +101,12 @@ fn ms(ms: u64) -> Duration {
fn wake() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (mut task, handle) = async_task::spawn(f, s);
+ let (mut runnable, handle) = async_task::spawn(f, s);
handle.detach();
assert!(chan.is_empty());
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
@@ -114,14 +114,14 @@ fn wake() {
assert_eq!(chan.len(), 0);
waker().wake();
- task = chan.recv().unwrap();
+ runnable = chan.recv().unwrap();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
assert_eq!(DROP_S.load(Ordering::SeqCst), 0);
assert_eq!(chan.len(), 0);
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -140,12 +140,12 @@ fn wake() {
fn wake_by_ref() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (mut task, handle) = async_task::spawn(f, s);
+ let (mut runnable, handle) = async_task::spawn(f, s);
handle.detach();
assert!(chan.is_empty());
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
@@ -153,14 +153,14 @@ fn wake_by_ref() {
assert_eq!(chan.len(), 0);
waker().wake_by_ref();
- task = chan.recv().unwrap();
+ runnable = chan.recv().unwrap();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
assert_eq!(DROP_S.load(Ordering::SeqCst), 0);
assert_eq!(chan.len(), 0);
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -179,10 +179,10 @@ fn wake_by_ref() {
fn clone() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (mut task, handle) = async_task::spawn(f, s);
+ let (mut runnable, handle) = async_task::spawn(f, s);
handle.detach();
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
@@ -194,8 +194,8 @@ fn clone() {
let w4 = w3.clone();
w4.wake();
- task = chan.recv().unwrap();
- task.run();
+ runnable = chan.recv().unwrap();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 2);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 1);
assert_eq!(DROP_F.load(Ordering::SeqCst), 1);
@@ -218,10 +218,10 @@ fn clone() {
fn wake_dropped() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
handle.detach();
- task.run();
+ runnable.run();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);
assert_eq!(DROP_F.load(Ordering::SeqCst), 0);
@@ -250,10 +250,10 @@ fn wake_dropped() {
fn wake_completed() {
future!(f, waker, POLL, DROP_F);
schedule!(s, chan, SCHEDULE, DROP_S);
- let (task, handle) = async_task::spawn(f, s);
+ let (runnable, handle) = async_task::spawn(f, s);
handle.detach();
- task.run();
+ runnable.run();
let w = waker();
assert_eq!(POLL.load(Ordering::SeqCst), 1);
assert_eq!(SCHEDULE.load(Ordering::SeqCst), 0);