diff options
author | Stephan Dilly <dilly.stephan@gmail.com> | 2021-09-02 18:29:03 +0200 |
---|---|---|
committer | Stephan Dilly <dilly.stephan@gmail.com> | 2021-09-02 18:29:03 +0200 |
commit | 40e03ba7de9243e59f600703ce95a04716a6d5b9 (patch) | |
tree | ee9f87b1b40bc665a1125ead0a4d416b225eec19 /src/ui | |
parent | 0454e2a1cdc4c8db90944fc7dbf1069c6d32555d (diff) |
allow async jobs to set intermediate progress
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/syntax_text.rs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/ui/syntax_text.rs b/src/ui/syntax_text.rs index c1b2f36c..70283067 100644 --- a/src/ui/syntax_text.rs +++ b/src/ui/syntax_text.rs @@ -1,5 +1,7 @@ -use asyncgit::{asyncjob::AsyncJob, ProgressPercent}; -use crossbeam_channel::Sender; +use asyncgit::{ + asyncjob::{AsyncJob, RunParams}, + ProgressPercent, +}; use lazy_static::lazy_static; use scopetime::scope_time; use std::{ @@ -70,7 +72,7 @@ impl SyntaxText { pub fn new( text: String, file_path: &Path, - sender: &Sender<AsyncAppNotification>, + params: &RunParams<AsyncAppNotification, ProgressPercent>, ) -> asyncgit::Result<Self> { scope_time!("syntax_highlighting"); log::debug!("syntax: {:?}", file_path); @@ -110,10 +112,9 @@ impl SyntaxText { total_count, Duration::from_millis(200), ); - sender.send(AsyncAppNotification::SyntaxHighlighting( - SyntaxHighlightProgress::Progress( - buffer.send_progress(), - ), + params.set_progress(buffer.send_progress())?; + params.send(AsyncAppNotification::SyntaxHighlighting( + SyntaxHighlightProgress::Progress, ))?; for (number, line) in text.lines().enumerate() { @@ -134,11 +135,10 @@ impl SyntaxText { }); if buffer.update(number) { - sender.send( + params.set_progress(buffer.send_progress())?; + params.send( AsyncAppNotification::SyntaxHighlighting( - SyntaxHighlightProgress::Progress( - buffer.send_progress(), - ), + SyntaxHighlightProgress::Progress, ), )?; } @@ -241,10 +241,11 @@ impl AsyncSyntaxJob { impl AsyncJob for AsyncSyntaxJob { type Notification = AsyncAppNotification; + type Progress = ProgressPercent; fn run( &mut self, - sender: Sender<Self::Notification>, + params: RunParams<Self::Notification, Self::Progress>, ) -> asyncgit::Result<Self::Notification> { let mut state_mutex = self.state.lock()?; @@ -254,7 +255,7 @@ impl AsyncJob for AsyncSyntaxJob { let syntax = SyntaxText::new( content, Path::new(&path), - &sender, + ¶ms, )?; JobState::Response(syntax) } |