Hello,
I am developing an application which does the following job:
* Read http request from client
* Parse request body from request
* Pass request body values via mpsc channel and returns immediate 'response' to the client. Another future will take care of reading messages from this mpsc channel and process them.
Sample code:
(&Method::Post, "/postTest") => {
Box::new(req.body().concat2().map(|b| {
let bad_request: &[u8] = b"Missing field";
let json: serde_json::Value =
if let Ok(j) = serde_json::from_slice(b.as_ref()) {
j
} else {
return Response::new().with_body(bad_request);
};
// use json value and send requests via mpsc channel
let cmd = format!("Test: {}", json["cmd"]);
tx_inst.clone().send(cmd.to_owned()).and_then(move |tx_inst| {
return Response::new()
.with_body("Success");
})
.or_else(|_| {
return Response::new()
.with_body("Failure");
})
}))
}
'tx_inst' is of type: mpsc::Sender
However the above code produces the following error.
The "tx_inst.clone().send" code works fine in a different context. It seems to have problem when it is chained like above. Tried replacing "and_then, or_else" part with "map, map_err". But this throws the following error.
Could anyone help me with this?