@@ -3,83 +3,41 @@ use std::future::Future;
3
3
use std:: pin:: Pin ;
4
4
use std:: sync:: Arc ;
5
5
6
- use tokio_executor:: { SpawnError , TypedExecutor } ;
7
-
8
6
use crate :: body:: { Payload , Body } ;
9
7
use crate :: proto:: h2:: server:: H2Stream ;
10
8
use crate :: server:: conn:: spawn_all:: { NewSvcTask , Watcher } ;
11
9
use crate :: service:: HttpService ;
12
10
13
11
pub trait H2Exec < F , B : Payload > : Clone {
14
- fn execute_h2stream ( & mut self , fut : H2Stream < F , B > ) -> crate :: Result < ( ) > ;
12
+ fn execute_h2stream ( & self , fut : H2Stream < F , B > ) ;
15
13
}
16
14
17
15
pub trait NewSvcExec < I , N , S : HttpService < Body > , E , W : Watcher < I , S , E > > : Clone {
18
- fn execute_new_svc ( & mut self , fut : NewSvcTask < I , N , S , E , W > ) -> crate :: Result < ( ) > ;
19
- }
20
-
21
- type BoxFuture = Pin < Box < dyn Future < Output =( ) > + Send > > ;
22
-
23
- pub trait SharedExecutor {
24
- fn shared_spawn ( & self , future : BoxFuture ) -> Result < ( ) , SpawnError > ;
16
+ fn execute_new_svc ( & self , fut : NewSvcTask < I , N , S , E , W > ) ;
25
17
}
26
18
27
- impl < E > SharedExecutor for E
28
- where
29
- for < ' a > & ' a E : tokio_executor:: Executor ,
30
- {
31
- fn shared_spawn ( mut self : & Self , future : BoxFuture ) -> Result < ( ) , SpawnError > {
32
- tokio_executor:: Executor :: spawn ( & mut self , future)
33
- }
34
- }
19
+ pub type BoxFuture = Pin < Box < dyn Future < Output =( ) > + Send > > ;
35
20
36
21
// Either the user provides an executor for background tasks, or we use
37
22
// `tokio::spawn`.
38
23
#[ derive( Clone ) ]
39
24
pub enum Exec {
40
25
Default ,
41
- Executor ( Arc < dyn SharedExecutor + Send + Sync > ) ,
26
+ Executor ( Arc < dyn Fn ( BoxFuture ) + Send + Sync > ) ,
42
27
}
43
28
44
29
// ===== impl Exec =====
45
30
46
31
impl Exec {
47
- pub ( crate ) fn execute < F > ( & self , fut : F ) -> crate :: Result < ( ) >
32
+ pub ( crate ) fn execute < F > ( & self , fut : F )
48
33
where
49
34
F : Future < Output =( ) > + Send + ' static ,
50
35
{
51
36
match * self {
52
37
Exec :: Default => {
53
38
#[ cfg( feature = "tcp" ) ]
54
39
{
55
- use std:: error:: Error as StdError ;
56
-
57
- struct TokioSpawnError ;
58
-
59
- impl fmt:: Debug for TokioSpawnError {
60
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
61
- fmt:: Debug :: fmt ( "tokio::spawn failed (is a tokio runtime running this future?)" , f)
62
- }
63
- }
64
-
65
- impl fmt:: Display for TokioSpawnError {
66
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
67
- fmt:: Display :: fmt ( "tokio::spawn failed (is a tokio runtime running this future?)" , f)
68
- }
69
- }
70
-
71
- impl StdError for TokioSpawnError {
72
- fn description ( & self ) -> & str {
73
- "tokio::spawn failed"
74
- }
75
- }
76
-
77
- :: tokio_executor:: DefaultExecutor :: current ( )
78
- . spawn ( Box :: pin ( fut) )
79
- . map_err ( |err| {
80
- warn ! ( "executor error: {:?}" , err) ;
81
- crate :: Error :: new_execute ( TokioSpawnError )
82
- } )
40
+ tokio:: spawn ( fut) ;
83
41
}
84
42
#[ cfg( not( feature = "tcp" ) ) ]
85
43
{
@@ -88,20 +46,18 @@ impl Exec {
88
46
}
89
47
} ,
90
48
Exec :: Executor ( ref e) => {
91
- e. shared_spawn ( Box :: pin ( fut) )
92
- . map_err ( |err| {
93
- warn ! ( "executor error: {:?}" , err) ;
94
- crate :: Error :: new_execute ( "custom executor failed" )
95
- } )
49
+ e ( Box :: pin ( fut) ) ;
96
50
} ,
97
51
}
98
52
}
99
53
}
100
54
101
55
impl fmt:: Debug for Exec {
102
56
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
103
- f. debug_struct ( "Exec" )
104
- . finish ( )
57
+ match self {
58
+ Exec :: Default => f. write_str ( "Exec::Default" ) ,
59
+ Exec :: Executor ( ..) => f. write_str ( "Exec::Custom" ) ,
60
+ }
105
61
}
106
62
}
107
63
111
67
H2Stream < F , B > : Future < Output = ( ) > + Send + ' static ,
112
68
B : Payload ,
113
69
{
114
- fn execute_h2stream ( & mut self , fut : H2Stream < F , B > ) -> crate :: Result < ( ) > {
70
+ fn execute_h2stream ( & self , fut : H2Stream < F , B > ) {
115
71
self . execute ( fut)
116
72
}
117
73
}
122
78
S : HttpService < Body > ,
123
79
W : Watcher < I , S , E > ,
124
80
{
125
- fn execute_new_svc ( & mut self , fut : NewSvcTask < I , N , S , E , W > ) -> crate :: Result < ( ) > {
81
+ fn execute_new_svc ( & self , fut : NewSvcTask < I , N , S , E , W > ) {
126
82
self . execute ( fut)
127
83
}
128
84
}
@@ -131,34 +87,23 @@ where
131
87
132
88
impl < E , F , B > H2Exec < F , B > for E
133
89
where
134
- E : TypedExecutor < H2Stream < F , B > > + Clone ,
90
+ E : Fn ( H2Stream < F , B > ) + Clone ,
135
91
H2Stream < F , B > : Future < Output =( ) > ,
136
92
B : Payload ,
137
93
{
138
- fn execute_h2stream ( & mut self , fut : H2Stream < F , B > ) -> crate :: Result < ( ) > {
139
- self . spawn ( fut)
140
- . map_err ( |err| {
141
- warn ! ( "executor error: {:?}" , err) ;
142
- crate :: Error :: new_execute ( "custom executor failed" )
143
- } )
94
+ fn execute_h2stream ( & self , fut : H2Stream < F , B > ) {
95
+ self ( fut) ;
144
96
}
145
97
}
146
98
147
99
impl < I , N , S , E , W > NewSvcExec < I , N , S , E , W > for E
148
100
where
149
- E : TypedExecutor < NewSvcTask < I , N , S , E , W > > + Clone ,
101
+ E : Fn ( NewSvcTask < I , N , S , E , W > ) + Clone ,
150
102
NewSvcTask < I , N , S , E , W > : Future < Output =( ) > ,
151
103
S : HttpService < Body > ,
152
104
W : Watcher < I , S , E > ,
153
105
{
154
- fn execute_new_svc ( & mut self , fut : NewSvcTask < I , N , S , E , W > ) -> crate :: Result < ( ) > {
155
- self . spawn ( fut)
156
- . map_err ( |err| {
157
- warn ! ( "executor error: {:?}" , err) ;
158
- crate :: Error :: new_execute ( "custom executor failed" )
159
- } )
106
+ fn execute_new_svc ( & self , fut : NewSvcTask < I , N , S , E , W > ) {
107
+ self ( fut) ;
160
108
}
161
109
}
162
-
163
- // ===== StdError impls =====
164
-
0 commit comments