@@ -7,12 +7,17 @@ use crossbeam_channel::Sender;
7
7
use std:: sync:: { Arc , Mutex , RwLock } ;
8
8
9
9
/// Passed to `AsyncJob::run` allowing sending intermediate progress notifications
10
- pub struct RunParams < T : Copy + Send , P : Clone + Send + Sync > {
10
+ pub struct RunParams <
11
+ T : Copy + Send ,
12
+ P : Clone + Send + Sync + PartialEq ,
13
+ > {
11
14
sender : Sender < T > ,
12
15
progress : Arc < RwLock < P > > ,
13
16
}
14
17
15
- impl < T : Copy + Send , P : Clone + Send + Sync > RunParams < T , P > {
18
+ impl < T : Copy + Send , P : Clone + Send + Sync + PartialEq >
19
+ RunParams < T , P >
20
+ {
16
21
/// send an intermediate update notification.
17
22
/// do not confuse this with the return value of `run`.
18
23
/// `send` should only be used about progress notifications
@@ -24,9 +29,13 @@ impl<T: Copy + Send, P: Clone + Send + Sync> RunParams<T, P> {
24
29
}
25
30
26
31
/// set the current progress
27
- pub fn set_progress ( & self , p : P ) -> Result < ( ) > {
28
- * ( self . progress . write ( ) ?) = p;
29
- Ok ( ( ) )
32
+ pub fn set_progress ( & self , p : P ) -> Result < bool > {
33
+ Ok ( if * self . progress . read ( ) ? == p {
34
+ false
35
+ } else {
36
+ * ( self . progress . write ( ) ?) = p;
37
+ true
38
+ } )
30
39
}
31
40
}
32
41
@@ -35,7 +44,7 @@ pub trait AsyncJob: Send + Sync + Clone {
35
44
/// defines what notification type is used to communicate outside
36
45
type Notification : Copy + Send ;
37
46
/// type of progress
38
- type Progress : Clone + Default + Send + Sync ;
47
+ type Progress : Clone + Default + Send + Sync + PartialEq ;
39
48
40
49
/// can run a synchronous time intensive task.
41
50
/// the returned notification is used to tell interested parties
0 commit comments