Skip to content

Commit

Permalink
WIP: task::scope
Browse files Browse the repository at this point in the history
This change adds task::scope as a mechanism for supporting
structured concurrency as described in tokio-rs#1879.

In this version of the change scopes can be created using a freestanding
`task::scope` function, which creates a new detached scope (which is not
coupled to the parent scope), `Scope::detached` and `Scope::with_parent`,
and a `::child()` method on an existing scope handle.

Since a few of of those methods are doing the same thing, some of those
might get dropped before the change is merged. For future extensibility
also a `Scope::with_config` and `ScopeConfigBuilder` are demonstrated in
this change. Those might also be part of the initial change.
  • Loading branch information
Matthias247 committed May 31, 2020
1 parent db0d6d7 commit 91b9f52
Show file tree
Hide file tree
Showing 7 changed files with 1,148 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tokio/Cargo.toml
Expand Up @@ -41,10 +41,12 @@ full = [
"rt-core",
"rt-util",
"rt-threaded",
"scope",
"signal",
"stream",
"sync",
"time",
"futures"
]

blocking = ["rt-core"]
Expand Down Expand Up @@ -73,6 +75,7 @@ rt-threaded = [
"num_cpus",
"rt-core",
]
scope = []
signal = [
"io-driver",
"lazy_static",
Expand All @@ -99,6 +102,7 @@ pin-project-lite = "0.1.1"
# Everything else is optional...
fnv = { version = "1.0.6", optional = true }
futures-core = { version = "0.3.0", optional = true }
futures = { version = "0.3.0", optional = true }
lazy_static = { version = "1.0.2", optional = true }
memchr = { version = "2.2", optional = true }
mio = { version = "0.6.20", optional = true }
Expand All @@ -122,7 +126,7 @@ optional = true

[dev-dependencies]
tokio-test = { version = "0.2.0", path = "../tokio-test" }
futures = { version = "0.3.0", features = ["async-await"] }
futures = { version = "0.3.0", features = ["async-await", "executor"] }
futures-test = "0.3.0"
proptest = "0.9.4"
tempfile = "3.1.0"
Expand Down
10 changes: 10 additions & 0 deletions tokio/src/macros/cfg.rs
Expand Up @@ -204,6 +204,16 @@ macro_rules! cfg_process {
}
}

macro_rules! cfg_scope {
($($item:item)*) => {
$(
#[cfg(feature = "scope")]
#[cfg_attr(docsrs, doc(cfg(feature = "scope")))]
$item
)*
}
}

macro_rules! cfg_signal {
($($item:item)*) => {
$(
Expand Down
5 changes: 5 additions & 0 deletions tokio/src/sync/mod.rs
Expand Up @@ -460,6 +460,11 @@ cfg_sync! {
mod task;
pub(crate) use task::AtomicWaker;

cfg_unstable! {
mod wait_group;
pub(crate) use wait_group::{SharedWaitGroup};
}

pub mod watch;
}

Expand Down

0 comments on commit 91b9f52

Please sign in to comment.