Added create document 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:
30
src/lib.rs
30
src/lib.rs
@@ -125,6 +125,36 @@ impl MTTClient {
|
||||
pub fn session_id(&self) -> String {
|
||||
self.session_id.to_string()
|
||||
}
|
||||
|
||||
pub fn create_document(&self, docdef: DocDef) -> Result<(), MTTError> {
|
||||
let msg_id = MessageID::new();
|
||||
let paths = [
|
||||
Path::new(
|
||||
Include::Just(msg_id.clone()),
|
||||
Include::All,
|
||||
Include::Just(Action::DocumentCreated),
|
||||
),
|
||||
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::with_id(msg_id.clone(), reg_msg));
|
||||
self.rx.recv().unwrap(); // Wait for completion.
|
||||
}
|
||||
self.queue.send(Message::with_id(msg_id.clone(), docdef));
|
||||
match self.rx.recv_timeout(TIMEOUT) {
|
||||
Ok(data) => match data.get_action() {
|
||||
MsgAction::DocumentCreated => Ok(()),
|
||||
MsgAction::Error(err) => Err(err.clone()),
|
||||
_ => unreachable!("should only receive confirmation or errors"),
|
||||
},
|
||||
Err(_) => Err(MTTError::new(ErrorID::TimeOut)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for MTTClient {
|
||||
|
||||
Reference in New Issue
Block a user