diff options
author | Eliza Weisman <eliza@buoyant.io> | 2019-11-26 17:03:18 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-26 17:03:18 -0800 |
commit | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd (patch) | |
tree | 2ca955e0737ce2b836d95f9329ad22befb1316a2 /tokio/src/sync/mod.rs | |
parent | 8e83a9f2c37fee3590d246b0420f688a0a9eea6b (diff) |
task: add `LocalSet` API for running `!Send` futures (#1733)
## Motivation
In earlier versions of `tokio`, the `current_thread::Runtime` type could
be used to run `!Send` futures. However, PR #1716 merged the
current-thread and threadpool runtimes into a single type, which can no
longer run `!Send` futures. There is still a need in some cases to
support futures that don't implement `Send`, and the `tokio-compat`
crate requires this in order to provide APIs that existed in `tokio`
0.1.
## Solution
This branch implements the API described by @carllerche in
https://github.com/tokio-rs/tokio/pull/1716#issuecomment-549496309. It
adds a new `LocalSet` type and `spawn_local` function to `tokio::task`.
The `LocalSet` type is used to group together a set of tasks which must
run on the same thread and don't implement `Send`. These are available
when a new "rt-util" feature flag is enabled.
Currently, the local task set is run by passing it a reference to a
`Runtime` and a future to `block_on`. In the future, we may also want
to investigate allowing spawned futures to construct their own local
task sets, which would be executed on the worker that the future is
executing on.
In order to implement the new API, I've made some internal changes to
the `task` module and `Schedule` trait to support scheduling both `Send`
and `!Send` futures.
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Diffstat (limited to 'tokio/src/sync/mod.rs')
-rw-r--r-- | tokio/src/sync/mod.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tokio/src/sync/mod.rs b/tokio/src/sync/mod.rs index 0db703bb..943f8f11 100644 --- a/tokio/src/sync/mod.rs +++ b/tokio/src/sync/mod.rs @@ -35,7 +35,7 @@ cfg_sync! { } cfg_not_sync! { - cfg_resource_drivers! { + cfg_atomic_waker_impl! { mod task; pub(crate) use task::AtomicWaker; } |