summaryrefslogtreecommitdiffstats
path: root/tokio-macros
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2019-11-16 07:19:45 -0800
committerGitHub <noreply@github.com>2019-11-16 07:19:45 -0800
commit3f0eabe7798de624f5ee9c7562803bfb97e6088f (patch)
tree6458345730f7eae674ec1e7ea82f120a5f1b70bc /tokio-macros
parent1474794055e291c544c3c95d6381d549cefbd7d5 (diff)
runtime: rename current_thread -> basic_scheduler (#1769)
It no longer supports executing !Send futures. The use case for It is wanting a “light” runtime. There will be “local” task execution using a different strategy coming later. This patch also renames `thread_pool` -> `threaded_scheduler`, but only in public APIs for now.
Diffstat (limited to 'tokio-macros')
-rw-r--r--tokio-macros/src/lib.rs53
1 files changed, 27 insertions, 26 deletions
diff --git a/tokio-macros/src/lib.rs b/tokio-macros/src/lib.rs
index 1cfc14c3..62c8d94b 100644
--- a/tokio-macros/src/lib.rs
+++ b/tokio-macros/src/lib.rs
@@ -18,9 +18,9 @@ extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;
-enum RuntimeType {
- Single,
- Multi,
+enum Runtime {
+ Basic,
+ Threaded,
Auto,
}
@@ -28,8 +28,8 @@ enum RuntimeType {
///
/// ## Options:
///
-/// - `current_thread` - Uses the `current_thread` runtime.
-/// - `threadpool` - Uses the multi-threaded `threadpool` runtime. Used by default.
+/// - `basic_scheduler` - All tasks are executed on the current thread.
+/// - `threaded_scheduler` - Uses the multi-threaded scheduler. Used by default.
///
/// ## Function arguments:
///
@@ -37,18 +37,19 @@ enum RuntimeType {
///
/// ## Usage
///
-/// ### Select runtime
+/// ### Using default
///
/// ```rust
-/// #[tokio::main(current_thread)]
+/// #[tokio::main]
/// async fn main() {
/// println!("Hello world");
/// }
/// ```
-/// ### Using default
+///
+/// ### Select runtime
///
/// ```rust
-/// #[tokio::main]
+/// #[tokio::main(basic_scheduler)]
/// async fn main() {
/// println!("Hello world");
/// }
@@ -77,7 +78,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
.into();
}
- let mut runtime = RuntimeType::Auto;
+ let mut runtime = Runtime::Auto;
for arg in args {
if let syn::NestedMeta::Meta(syn::Meta::Path(path)) = arg {
@@ -87,10 +88,10 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
return syn::Error::new_spanned(path, msg).to_compile_error().into();
}
match ident.unwrap().to_string().to_lowercase().as_str() {
- "threadpool" => runtime = RuntimeType::Multi,
- "current_thread" => runtime = RuntimeType::Single,
+ "threaded_scheduler" => runtime = Runtime::Threaded,
+ "basic_scheduler" => runtime = Runtime::Basic,
name => {
- let msg = format!("Unknown attribute {} is specified; expected `current_thread` or `threadpool`", name);
+ let msg = format!("Unknown attribute {} is specified; expected `basic_scheduler` or `threaded_scheduler`", name);
return syn::Error::new_spanned(path, msg).to_compile_error().into();
}
}
@@ -98,17 +99,17 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
}
let result = match runtime {
- RuntimeType::Multi | RuntimeType::Auto => quote! {
+ Runtime::Threaded | Runtime::Auto => quote! {
#(#attrs)*
fn #name(#inputs) #ret {
tokio::runtime::Runtime::new().unwrap().block_on(async { #body })
}
},
- RuntimeType::Single => quote! {
+ Runtime::Basic => quote! {
#(#attrs)*
fn #name(#inputs) #ret {
tokio::runtime::Builder::new()
- .current_thread()
+ .basic_scheduler()
.build()
.unwrap()
.block_on(async { #body })
@@ -123,15 +124,15 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
///
/// ## Options:
///
-/// - `current_thread` - Uses the `current_thread` runtime. Used by default.
-/// - `threadpool` - Uses multi-threaded runtime.
+/// - `basic_scheduler` - All tasks are executed on the current thread. Used by default.
+/// - `threaded_scheduler` - Use multi-threaded scheduler.
///
/// ## Usage
///
/// ### Select runtime
///
/// ```no_run
-/// #[tokio::test(threadpool)]
+/// #[tokio::test(threaded_scheduler)]
/// async fn my_test() {
/// assert!(true);
/// }
@@ -176,7 +177,7 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
.into();
}
- let mut runtime = RuntimeType::Auto;
+ let mut runtime = Runtime::Auto;
for arg in args {
if let syn::NestedMeta::Meta(syn::Meta::Path(path)) = arg {
@@ -186,10 +187,10 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
return syn::Error::new_spanned(path, msg).to_compile_error().into();
}
match ident.unwrap().to_string().to_lowercase().as_str() {
- "threadpool" => runtime = RuntimeType::Multi,
- "current_thread" => runtime = RuntimeType::Single,
+ "threaded_scheduler" => runtime = Runtime::Threaded,
+ "basic_scheduler" => runtime = Runtime::Basic,
name => {
- let msg = format!("Unknown attribute {} is specified; expected `current_thread` or `threadpool`", name);
+ let msg = format!("Unknown attribute {} is specified; expected `basic_scheduler` or `threaded_scheduler`", name);
return syn::Error::new_spanned(path, msg).to_compile_error().into();
}
}
@@ -197,19 +198,19 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
}
let result = match runtime {
- RuntimeType::Multi => quote! {
+ Runtime::Threaded => quote! {
#[test]
#(#attrs)*
fn #name() #ret {
tokio::runtime::Runtime::new().unwrap().block_on(async { #body })
}
},
- RuntimeType::Single | RuntimeType::Auto => quote! {
+ Runtime::Basic | Runtime::Auto => quote! {
#[test]
#(#attrs)*
fn #name() #ret {
tokio::runtime::Builder::new()
- .current_thread()
+ .basic_scheduler()
.build()
.unwrap()
.block_on(async { #body })