@@ -199,7 +199,7 @@ public class Task<Progress, Value, Error>
199199 }
200200
201201 // TODO: how to nest these inside StateMachine's initClosure? (using `self` is not permitted)
202- // NOTE: use order > 100 (default) to let `progressClosure(self.progress, newValue )` be invoked first before updating old `self.progress`
202+ // NOTE: use order > 100 (default) to let `progressClosure(self.progress, newProgress )` be invoked first before updating old `self.progress`
203203 self . machine. addEventHandler ( . Progress, order: 110 ) { [ weak self] context in
204204 if let progress = context. userInfo as? Progress {
205205 if let self_ = self {
@@ -278,33 +278,32 @@ public class Task<Progress, Value, Error>
278278 self . _cancel ( error: nil )
279279 }
280280
281- /// task.onProgress
282- public func onProgress( progressClosure: ( oldValue: Progress ? , newValue: Progress ) -> Void ) -> Task
281+ public func progress( progressClosure: ( oldProgress: Progress ? , newProgress: Progress ) -> Void ) -> Task
283282 {
284283 self . machine. addEventHandler ( . Progress) { [ weak self] context in
285284 if let progress = context. userInfo as? Progress {
286- progressClosure ( oldValue : self ? . progress, newValue : progress)
285+ progressClosure ( oldProgress : self ? . progress, newProgress : progress)
287286 }
288287 }
289288
290289 return self
291290 }
292291
293- /// onComplete (fulfilled & rejected) + closure returning value
294- public func onComplete < Value2> ( completeClosure : ( Value ? , ErrorInfo ? ) -> Value2 ) -> Task < Progress , Value2 , Error >
292+ /// then (fulfilled & rejected) + closure returning value
293+ public func then < Value2> ( thenClosure : ( Value ? , ErrorInfo ? ) -> Value2 ) -> Task < Progress , Value2 , Error >
295294 {
296- return self . onComplete { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Task < Progress , Value2 , Error > in
297- return Task < Progress , Value2 , Error > ( value: completeClosure ( value, errorInfo) )
295+ return self . then { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Task < Progress , Value2 , Error > in
296+ return Task < Progress , Value2 , Error > ( value: thenClosure ( value, errorInfo) )
298297 }
299298 }
300299
301- /// onComplete (fulfilled & rejected) + closure returning task
302- public func onComplete < Progress2, Value2> ( completeClosure : ( Value ? , ErrorInfo ? ) -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
300+ /// then (fulfilled & rejected) + closure returning task
301+ public func then < Progress2, Value2> ( thenClosure : ( Value ? , ErrorInfo ? ) -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
303302 {
304303 let newTask = Task < Progress2 , Value2 , Error > { [ weak self] ( progress, fulfill, _reject: _RejectHandler , configure) in
305304
306305 let bind = { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Void in
307- let innerTask = completeClosure ( value, errorInfo)
306+ let innerTask = thenClosure ( value, errorInfo)
308307
309308 // NOTE: don't call `then` for innerTask, or recursive bindings may occur
310309 // Bad example: https://github.com/inamiy/SwiftTask/blob/e6085465c147fb2211fb2255c48929fcc07acd6d/SwiftTask/SwiftTask.swift#L312-L316
@@ -356,23 +355,23 @@ public class Task<Progress, Value, Error>
356355 return newTask
357356 }
358357
359- /// onSuccess + closure returning value
360- public func onSuccess < Value2> ( fulfilledClosure: Value -> Value2 ) -> Task < Progress , Value2 , Error >
358+ /// success (fulfilled) + closure returning value
359+ public func success < Value2> ( fulfilledClosure: Value -> Value2 ) -> Task < Progress , Value2 , Error >
361360 {
362- return self . onSuccess { ( value: Value ) -> Task < Progress , Value2 , Error > in
361+ return self . success { ( value: Value ) -> Task < Progress , Value2 , Error > in
363362 return Task < Progress , Value2 , Error > ( value: fulfilledClosure ( value) )
364363 }
365364 }
366365
367- /// onSuccess + closure returning task
368- public func onSuccess < Progress2, Value2> ( fulfilledClosure: Value -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
366+ /// success (fulfilled) + closure returning task
367+ public func success < Progress2, Value2> ( fulfilledClosure: Value -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
369368 {
370369 let newTask = Task < Progress2 , Value2 , Error > { [ weak self] ( progress, fulfill, _reject: _RejectHandler , configure) in
371370
372371 let bind = { ( value: Value ) -> Void in
373372 let innerTask = fulfilledClosure ( value)
374373
375- innerTask. onComplete { ( value: Value2 ? , errorInfo: ErrorInfo ? ) -> Void in
374+ innerTask. then { ( value: Value2 ? , errorInfo: ErrorInfo ? ) -> Void in
376375 if let value = value {
377376 fulfill ( value)
378377 }
@@ -411,23 +410,23 @@ public class Task<Progress, Value, Error>
411410 return newTask
412411 }
413412
414- /// onFailure + closure returning value
415- public func onFailure ( failureClosure: ErrorInfo -> Value ) -> Task
413+ /// failure (rejected) + closure returning value
414+ public func failure ( failureClosure: ErrorInfo -> Value ) -> Task
416415 {
417- return self . onFailure { ( errorInfo: ErrorInfo ) -> Task in
416+ return self . failure { ( errorInfo: ErrorInfo ) -> Task in
418417 return Task ( value: failureClosure ( errorInfo) )
419418 }
420419 }
421420
422- /// onFailure + closure returning task
423- public func onFailure ( failureClosure: ErrorInfo -> Task ) -> Task
421+ /// failure (rejected) + closure returning task
422+ public func failure ( failureClosure: ErrorInfo -> Task ) -> Task
424423 {
425424 let newTask = Task { [ weak self] ( progress, fulfill, _reject: _RejectHandler , configure) in
426425
427426 let bind = { ( errorInfo: ErrorInfo ) -> Void in
428427 let innerTask = failureClosure ( errorInfo)
429428
430- innerTask. onComplete { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Void in
429+ innerTask. then { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Void in
431430 if let value = value {
432431 fulfill ( value)
433432 }
@@ -498,7 +497,7 @@ extension Task
498497 let totalCount = tasks. count
499498
500499 for task in tasks {
501- task. onSuccess { ( value: Value ) -> Void in
500+ task. success { ( value: Value ) -> Void in
502501
503502 synchronized ( self ) {
504503 completedCount++
@@ -517,7 +516,7 @@ extension Task
517516 }
518517 }
519518
520- } . onFailure { ( errorInfo: ErrorInfo ) -> Void in
519+ } . failure { ( errorInfo: ErrorInfo ) -> Void in
521520
522521 synchronized ( self ) {
523522 _reject ( errorInfo)
@@ -545,7 +544,7 @@ extension Task
545544 let totalCount = tasks. count
546545
547546 for task in tasks {
548- task. onSuccess { ( value: Value ) -> Void in
547+ task. success { ( value: Value ) -> Void in
549548
550549 synchronized ( self ) {
551550 completedCount++
@@ -557,7 +556,7 @@ extension Task
557556 }
558557 }
559558
560- } . onFailure { ( errorInfo: ErrorInfo ) -> Void in
559+ } . failure { ( errorInfo: ErrorInfo ) -> Void in
561560
562561 synchronized ( self ) {
563562 rejectedCount++
@@ -589,7 +588,7 @@ extension Task
589588 let totalCount = tasks. count
590589
591590 for task in tasks {
592- task. onComplete { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Void in
591+ task. then { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Void in
593592
594593 synchronized ( self ) {
595594 completedCount++
0 commit comments