From c036827154172d77ac26408e60e1161457bc71b2 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 8 Nov 2016 08:09:38 +1000 Subject: [PATCH] more simple usage tweaks --- src/main.rs | 55 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/main.rs b/src/main.rs index a8f50cb..a41dae3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,34 +30,41 @@ lazy_static! { } fn main() { - //Build a client - let cli = ClientBuilder::new(&QUEUE) + // Build a client + let builder = ClientBuilder::new(&QUEUE) .connect_localhost() - .build() - .wait() - .unwrap(); + .connect_localhost() + .build(); + + // Index some data + let post = builder.and_then(|cli| { + 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::finished(cli) + }) + }); - 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) - } + // Search some data + let search = post.and_then(|cli| { + futures::collect((0..5).map(move |_| { + cli.req(Request::get("/testindex/testtype/_search")) + .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(()) + }) + })) + }); - futures::finished(()) - }) - })) - }) - .wait() - .unwrap(); + search.wait().unwrap(); } fn print_res(res: Vec) {