Skip to content

Commit

Permalink
more simple usage tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Nov 7, 2016
1 parent 18ade66 commit c036827
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) {
Expand Down

0 comments on commit c036827

Please sign in to comment.