1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! ## Pending actions
//!
//! this little module exposes the routine to create a pending action on the file transfer activity.
//! A pending action is an action which blocks the execution of the application in await of a certain `Msg`.
use tuirealm::application::PollStrategy;
use super::{FileTransferActivity, Msg};
impl FileTransferActivity {
/// Block execution of activity, preventing ANY kind of message not specified in the `wait_for` argument.
/// Once `wait_for` clause is satisfied, the function returns.
///
/// Returns the message which satisfied the clause
///
/// NOTE: The view is redrawn as usual
pub(super) fn wait_for_pending_msg(&mut self, wait_for: &[Msg]) -> Msg {
self.redraw = true;
loop {
// Poll
match self
.app
.tick(PollStrategy::Once(std::time::Duration::from_millis(10)))
{
Ok(mut messages) => {
if !messages.is_empty() {
self.redraw = true;
}
let found = messages.iter().position(|m| wait_for.contains(m));
// Return if found
if let Some(index) = found {
return messages.remove(index);
} else {
// Update
for msg in messages.into_iter() {
let mut msg = Some(msg);
while msg.is_some() {
msg = self.update(msg);
}
}
}
}
Err(err) => {
error!("Application error: {}", err);
}
}
// Redraw
if self.redraw {
self.view();
}
}
}
}