Skip to content

Commit 4f1f110

Browse files
tstackttiimm
authored andcommitted
[progress] add support for polling the ProgressListener with a timeout
There's a thread in lnav that needs to poll for progress and can't block waiting for an update.
1 parent a63ee3a commit 4f1f110

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use code_source::CodeSource;
2727
use log_format::LogFormat;
2828
pub use progress::ProgressTracker;
2929
pub use progress::ProgressUpdate;
30+
pub use progress::WorkInfo;
3031
use source_query::QueryResult;
3132
pub use source_query::SourceQuery;
3233
pub use source_ref::SourceRef;

src/progress.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::sync::atomic::{AtomicU64, Ordering};
22
use std::sync::mpsc::{channel, Receiver, Sender};
33
use std::sync::Arc;
4+
use std::time::Duration;
45

56
pub struct WorkInfo {
67
pub completed: AtomicU64,
@@ -117,3 +118,9 @@ impl Iterator for ProgressListener {
117118
self.receiver.iter().next()
118119
}
119120
}
121+
122+
impl ProgressListener {
123+
pub fn try_next_for(&self, timeout: Duration) -> Option<ProgressUpdate> {
124+
self.receiver.recv_timeout(timeout).ok()
125+
}
126+
}

0 commit comments

Comments
 (0)