Added records function to client.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
47
src/lib.rs
47
src/lib.rs
@@ -155,6 +155,53 @@ impl MTTClient {
|
||||
Err(_) => Err(MTTError::new(ErrorID::TimeOut)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn records<UA>(&self, request: UA) -> Result<Records, MTTError>
|
||||
where
|
||||
UA: Into<ClientAction>,
|
||||
{
|
||||
let req = request.into();
|
||||
let doc_id = req.doc_name().clone();
|
||||
let msg_id = MessageID::new();
|
||||
let paths = [
|
||||
Path::new(
|
||||
Include::Just(msg_id.clone()),
|
||||
Include::Just(doc_id.clone()),
|
||||
Include::Just(Action::Records),
|
||||
),
|
||||
Path::new(
|
||||
Include::Just(msg_id.clone()),
|
||||
Include::All,
|
||||
Include::Just(Action::Error),
|
||||
),
|
||||
];
|
||||
for path in paths.iter() {
|
||||
let reg_msg = Register::new(self.sender_id.clone(), RegMsg::AddRoute(path.clone()));
|
||||
self.queue.send(Message::new(reg_msg));
|
||||
let result = self.rx.recv().unwrap();
|
||||
let action = result.get_action();
|
||||
match action {
|
||||
MsgAction::Register(status) => match status.get_msg() {
|
||||
RegMsg::Error(err) => {
|
||||
let mut error = err.clone();
|
||||
error.add_parent(ErrorID::Document(doc_id.clone()));
|
||||
return Err(error);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => unreachable!("got {:?} should have been a registry message", action),
|
||||
}
|
||||
}
|
||||
self.queue.send(Message::with_id(msg_id, req));
|
||||
match self.rx.recv_timeout(TIMEOUT) {
|
||||
Ok(data) => match data.get_action() {
|
||||
MsgAction::Records(data) => Ok(data.clone()),
|
||||
MsgAction::Error(err) => Err(err.clone()),
|
||||
_ => unreachable!("should only receive records or errors"),
|
||||
},
|
||||
Err(_) => Err(MTTError::new(ErrorID::TimeOut)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for MTTClient {
|
||||
|
||||
Reference in New Issue
Block a user