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