Skip to content

Commit

Permalink
tweak sample around a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Nov 7, 2016
1 parent df7f766 commit 078cc0d
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,36 @@ lazy_static! {

fn main() {
//Build a client
let builder = ClientBuilder::new(&QUEUE)
.connect_localhost();

let cli = builder.build().wait().unwrap();

//Run a post request asynchronously
cli.req(Request::post("/testindex/testtype/1", b"{\"id\":1}"))
let cli = ClientBuilder::new(&QUEUE)
.connect_localhost()
.build()
.wait()
.unwrap()
.unwrap();

//Run some search requests asynchronously
let total_reqs = 100;
let search_reqs: Vec<ResponseFuture> = (0..total_reqs).map(|_| {
cli.req(Request::get("/testindex/testtype/_search"))
}).collect();
cli.req(Request::post("/testindex/testtype/1", b"{\"id\":1}"))
.and_then(|result| {
match result {
Ok(data) => print_res(data),
Err(e) => println!("Error: {}", e)
}

futures::collect((0..5).map(|_| {
cli.req(Request::get("/testindex/testtype/_search"))
.and_then(|result| {
match result {
Ok(data) => print_res(data),
Err(e) => println!("Error: {}", e)
}

futures::finished(())
})
}))
})
.wait()
.unwrap();
}

futures::collect(search_reqs).wait().unwrap();
fn print_res(res: Vec<u8>) {
let res = ::std::str::from_utf8(&res).unwrap();
println!("{}", res);
}

0 comments on commit 078cc0d

Please sign in to comment.