mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
runtime: merge multi & single threaded runtimes (#1716)
Simplify Tokio's runtime construct by combining both Runtime variants into a single type. The execution style can be controlled by a configuration setting on `Builder`. The implication of this change is that there is no longer any way to spawn `!Send` futures. This, however, is a temporary limitation. A different strategy will be employed for supporting `!Send` futures. Included in this patch is a rework of `task::JoinHandle` to support using this type from both the thread-pool and current-thread executors.
This commit is contained in:
+11
-10
@@ -98,7 +98,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
let result = match runtime {
|
||||
RuntimeType::Multi => quote! {
|
||||
RuntimeType::Multi | RuntimeType::Auto => quote! {
|
||||
#(#attrs)*
|
||||
fn #name(#inputs) #ret {
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async { #body })
|
||||
@@ -107,14 +107,11 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||
RuntimeType::Single => quote! {
|
||||
#(#attrs)*
|
||||
fn #name(#inputs) #ret {
|
||||
tokio::runtime::current_thread::Runtime::new().unwrap().block_on(async { #body })
|
||||
}
|
||||
},
|
||||
RuntimeType::Auto => quote! {
|
||||
#(#attrs)*
|
||||
fn #name() #ret {
|
||||
let mut rt = tokio::runtime::__main::Runtime::new().unwrap();
|
||||
rt.block_on(async { #body })
|
||||
tokio::runtime::Builder::new()
|
||||
.current_thread()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async { #body })
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -211,7 +208,11 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||
#[test]
|
||||
#(#attrs)*
|
||||
fn #name() #ret {
|
||||
tokio::runtime::current_thread::Runtime::new().unwrap().block_on(async { #body })
|
||||
tokio::runtime::Builder::new()
|
||||
.current_thread()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async { #body })
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user