From 3f0eabe7798de624f5ee9c7562803bfb97e6088f Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Sat, 16 Nov 2019 07:19:45 -0800 Subject: runtime: rename current_thread -> basic_scheduler (#1769) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tokio-macros/src/lib.rs | 53 +++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'tokio-macros') 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 }) -- cgit v1.2.3