@@ -93,8 +93,13 @@ public class Task<Progress, Value, Error>
9393
9494 internal var machine : Machine !
9595
96+ /// progress value
9697 public internal( set) var progress : Progress ?
98+
99+ /// fulfilled value
97100 public internal( set) var value : Value ?
101+
102+ /// rejected/cancelled tuple info
98103 public internal( set) var errorInfo : ErrorInfo ?
99104
100105 public var state : TaskState
@@ -194,7 +199,8 @@ public class Task<Progress, Value, Error>
194199 }
195200
196201 // TODO: how to nest these inside StateMachine's initClosure? (using `self` is not permitted)
197- self . machine. addEventHandler ( . Progress, order: 90 ) { [ weak self] context in
202+ // NOTE: use order > 100 (default) to let `progressTupleClosure(self.progress, newValue)` be invoked first before updating old `self.progress`
203+ self . machine. addEventHandler ( . Progress, order: 110 ) { [ weak self] context in
198204 if let progress = context. userInfo as? Progress {
199205 if let self_ = self {
200206 self_. progress = progress
@@ -272,6 +278,7 @@ public class Task<Progress, Value, Error>
272278 self . _cancel ( error: nil )
273279 }
274280
281+ /// progress + newValue only
275282 public func progress( progressClosure: Progress -> Void ) -> Task
276283 {
277284 self . machine. addEventHandler ( . Progress) { [ weak self] context in
@@ -283,6 +290,20 @@ public class Task<Progress, Value, Error>
283290 return self
284291 }
285292
293+ /// progress + (oldValue, newValue)
294+ public func progress( progressTupleClosure: ( oldValue: Progress ? , newValue: Progress ) -> Void ) -> Task
295+ {
296+ self . machine. addEventHandler ( . Progress) { [ weak self] context in
297+ if let progress = context. userInfo as? Progress {
298+ if let self_ = self {
299+ progressTupleClosure ( oldValue: self_. progress, newValue: progress)
300+ }
301+ }
302+ }
303+
304+ return self
305+ }
306+
286307 /// then (fulfilled & rejected) + returning value
287308 public func then< Value2> ( thenClosure: ( Value ? , ErrorInfo ? ) -> Value2 ) -> Task < Progress , Value2 , Error >
288309 {
0 commit comments