@@ -8,7 +8,8 @@ extern crate tokio;
8
8
9
9
use std:: net:: SocketAddr ;
10
10
11
- use futures:: { Future , Stream } ;
11
+ use futures:: { FutureExt , StreamExt } ;
12
+ use futures:: executor:: block_on;
12
13
use tokio:: runtime:: Runtime ;
13
14
use tokio:: net:: TcpListener ;
14
15
@@ -22,19 +23,20 @@ fn get_one_at_a_time(b: &mut test::Bencher) {
22
23
let addr = spawn_hello ( & mut rt) ;
23
24
24
25
let client = hyper:: Client :: configure ( )
25
- . build_with_executor ( & rt. handle ( ) , rt . executor ( ) ) ;
26
+ . build ( & rt. handle ( ) ) ;
26
27
27
28
let url: hyper:: Uri = format ! ( "http://{}/get" , addr) . parse ( ) . unwrap ( ) ;
28
29
29
30
b. bytes = 160 * 2 + PHRASE . len ( ) as u64 ;
30
31
b. iter ( move || {
31
- client. get ( url. clone ( ) )
32
+ block_on ( client. get ( url. clone ( ) )
33
+ . with_executor ( rt. executor ( ) )
32
34
. and_then ( |res| {
33
35
res. into_body ( ) . into_stream ( ) . for_each ( |_chunk| {
34
36
Ok ( ( ) )
35
- } )
37
+ } ) . map ( |_| ( ) )
36
38
} )
37
- . wait ( ) . expect ( "client wait" ) ;
39
+ ) . expect ( "client wait" ) ;
38
40
} ) ;
39
41
}
40
42
@@ -44,7 +46,7 @@ fn post_one_at_a_time(b: &mut test::Bencher) {
44
46
let addr = spawn_hello ( & mut rt) ;
45
47
46
48
let client = hyper:: Client :: configure ( )
47
- . build_with_executor ( & rt. handle ( ) , rt . executor ( ) ) ;
49
+ . build ( & rt. handle ( ) ) ;
48
50
49
51
let url: hyper:: Uri = format ! ( "http://{}/post" , addr) . parse ( ) . unwrap ( ) ;
50
52
@@ -54,11 +56,14 @@ fn post_one_at_a_time(b: &mut test::Bencher) {
54
56
let mut req = Request :: new ( post. into ( ) ) ;
55
57
* req. method_mut ( ) = Method :: POST ;
56
58
* req. uri_mut ( ) = url. clone ( ) ;
57
- client. request ( req) . and_then ( |res| {
58
- res. into_body ( ) . into_stream ( ) . for_each ( |_chunk| {
59
- Ok ( ( ) )
59
+ block_on ( client. request ( req)
60
+ . with_executor ( rt. executor ( ) )
61
+ . and_then ( |res| {
62
+ res. into_body ( ) . into_stream ( ) . for_each ( |_chunk| {
63
+ Ok ( ( ) )
64
+ } ) . map ( |_| ( ) )
60
65
} )
61
- } ) . wait ( ) . expect ( "client wait" ) ;
66
+ ) . expect ( "client wait" ) ;
62
67
63
68
} ) ;
64
69
}
@@ -76,21 +81,22 @@ fn spawn_hello(rt: &mut Runtime) -> SocketAddr {
76
81
let service = const_service ( service_fn ( |req : Request < Body > | {
77
82
req. into_body ( )
78
83
. into_stream ( )
79
- . concat2 ( )
84
+ . concat ( )
80
85
. map ( |_| {
81
86
Response :: new ( Body :: from ( PHRASE ) )
82
87
} )
83
88
} ) ) ;
84
89
85
90
let srv = listener. incoming ( )
86
- . into_future ( )
91
+ . next ( )
87
92
. map_err ( |( e, _inc) | panic ! ( "accept error: {}" , e) )
88
93
. and_then ( move |( accepted, _inc) | {
89
94
let socket = accepted. expect ( "accepted socket" ) ;
90
95
http. serve_connection ( socket, service. new_service ( ) . expect ( "new_service" ) )
91
96
. map ( |_| ( ) )
92
97
. map_err ( |_| ( ) )
93
- } ) ;
94
- rt. spawn ( srv) ;
98
+ } )
99
+ . map_err ( |_| panic ! ( "server error" ) ) ;
100
+ rt. spawn2 ( srv) ;
95
101
return addr
96
102
}
0 commit comments