@@ -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 `progressTupleClosure (self.progress, newValue)` be invoked first before updating old `self.progress`
202+ // NOTE: use order > 100 (default) to let `progressClosure (self.progress, newValue)` 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,49 +278,37 @@ public class Task<Progress, Value, Error>
278278 self . _cancel ( error: nil )
279279 }
280280
281- /// progress + newValue only
282- public func progress( progressClosure: Progress -> Void ) -> Task
283- {
284- self . machine. addEventHandler ( . Progress) { [ weak self] context in
285- if let progress = context. userInfo as? Progress {
286- progressClosure ( progress)
287- }
288- }
289-
290- return self
291- }
292-
293- /// progress + (oldValue, newValue)
294- public func progress( progressTupleClosure: ( oldValue: Progress ? , newValue: Progress ) -> Void ) -> Task
281+ /// task.onProgress
282+ public func onProgress( progressClosure: ( oldValue: Progress ? , newValue: Progress ) -> Void ) -> Task
295283 {
296284 self . machine. addEventHandler ( . Progress) { [ weak self] context in
297285 if let progress = context. userInfo as? Progress {
298286 if let self_ = self {
299- progressTupleClosure ( oldValue: self_. progress, newValue: progress)
287+ progressClosure ( oldValue: self_. progress, newValue: progress)
300288 }
301289 }
302290 }
303291
304292 return self
305293 }
306294
307- /// then (fulfilled & rejected) + returning value
308- public func then < Value2> ( thenClosure : ( Value ? , ErrorInfo ? ) -> Value2 ) -> Task < Progress , Value2 , Error >
295+ /// onComplete (fulfilled & rejected) + closure returning value
296+ public func onComplete < Value2> ( completeClosure : ( Value ? , ErrorInfo ? ) -> Value2 ) -> Task < Progress , Value2 , Error >
309297 {
310- return self . then { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Task < Progress , Value2 , Error > in
311- return Task < Progress , Value2 , Error > ( value: thenClosure ( value, errorInfo) )
298+ return self . onComplete { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Task < Progress , Value2 , Error > in
299+ return Task < Progress , Value2 , Error > ( value: completeClosure ( value, errorInfo) )
312300 }
313301 }
314302
315- /// then (fulfilled & rejected) + returning task
316- public func then < Progress2, Value2> ( thenClosure : ( Value ? , ErrorInfo ? ) -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
303+ /// onComplete (fulfilled & rejected) + closure returning task
304+ public func onComplete < Progress2, Value2> ( completeClosure : ( Value ? , ErrorInfo ? ) -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
317305 {
318306 let newTask = Task < Progress2 , Value2 , Error > { [ weak self] ( progress, fulfill, _reject: _RejectHandler , configure) in
319307
320308 let bind = { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Void in
321- let innerTask = thenClosure ( value, errorInfo)
309+ let innerTask = completeClosure ( value, errorInfo)
322310
323- // NOTE: don't call then/catch for innerTask, or recursive bindings may occur
311+ // NOTE: don't call ` then` for innerTask, or recursive bindings may occur
324312 // Bad example: https://github.com/inamiy/SwiftTask/blob/e6085465c147fb2211fb2255c48929fcc07acd6d/SwiftTask/SwiftTask.swift#L312-L316
325313 switch innerTask. machine. state {
326314 case . Fulfilled:
@@ -370,23 +358,23 @@ public class Task<Progress, Value, Error>
370358 return newTask
371359 }
372360
373- /// then (fulfilled only) + returning value
374- public func then < Value2> ( fulfilledClosure: Value -> Value2 ) -> Task < Progress , Value2 , Error >
361+ /// onSuccess + closure returning value
362+ public func onSuccess < Value2> ( fulfilledClosure: Value -> Value2 ) -> Task < Progress , Value2 , Error >
375363 {
376- return self . then { ( value: Value ) -> Task < Progress , Value2 , Error > in
364+ return self . onSuccess { ( value: Value ) -> Task < Progress , Value2 , Error > in
377365 return Task < Progress , Value2 , Error > ( value: fulfilledClosure ( value) )
378366 }
379367 }
380368
381- /// then (fulfilled only) + returning task
382- public func then < Progress2, Value2> ( fulfilledClosure: Value -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
369+ /// onSuccess + closure returning task
370+ public func onSuccess < Progress2, Value2> ( fulfilledClosure: Value -> Task < Progress2 , Value2 , Error > ) -> Task < Progress2 , Value2 , Error >
383371 {
384372 let newTask = Task < Progress2 , Value2 , Error > { [ weak self] ( progress, fulfill, _reject: _RejectHandler , configure) in
385373
386374 let bind = { ( value: Value ) -> Void in
387375 let innerTask = fulfilledClosure ( value)
388376
389- innerTask. then { ( value: Value2 ? , errorInfo: ErrorInfo ? ) -> Void in
377+ innerTask. onComplete { ( value: Value2 ? , errorInfo: ErrorInfo ? ) -> Void in
390378 if let value = value {
391379 fulfill ( value)
392380 }
@@ -425,23 +413,23 @@ public class Task<Progress, Value, Error>
425413 return newTask
426414 }
427415
428- /// catch + returning value
429- public func catch ( catchClosure : ErrorInfo -> Value ) -> Task
416+ /// onFailure + closure returning value
417+ public func onFailure ( failureClosure : ErrorInfo -> Value ) -> Task
430418 {
431- return self . catch { ( errorInfo: ErrorInfo ) -> Task in
432- return Task ( value: catchClosure ( errorInfo) )
419+ return self . onFailure { ( errorInfo: ErrorInfo ) -> Task in
420+ return Task ( value: failureClosure ( errorInfo) )
433421 }
434422 }
435423
436- /// catch + returning task
437- public func catch ( catchClosure : ErrorInfo -> Task ) -> Task
424+ /// onFailure + closure returning task
425+ public func onFailure ( failureClosure : ErrorInfo -> Task ) -> Task
438426 {
439427 let newTask = Task { [ weak self] ( progress, fulfill, _reject: _RejectHandler , configure) in
440428
441429 let bind = { ( errorInfo: ErrorInfo ) -> Void in
442- let innerTask = catchClosure ( errorInfo)
430+ let innerTask = failureClosure ( errorInfo)
443431
444- innerTask. then { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Void in
432+ innerTask. onComplete { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Void in
445433 if let value = value {
446434 fulfill ( value)
447435 }
@@ -512,7 +500,7 @@ extension Task
512500 let totalCount = tasks. count
513501
514502 for task in tasks {
515- task. then { ( value: Value ) -> Void in
503+ task. onSuccess { ( value: Value ) -> Void in
516504
517505 synchronized ( self ) {
518506 completedCount++
@@ -531,7 +519,7 @@ extension Task
531519 }
532520 }
533521
534- } . catch { ( errorInfo: ErrorInfo ) -> Void in
522+ } . onFailure { ( errorInfo: ErrorInfo ) -> Void in
535523
536524 synchronized ( self ) {
537525 _reject ( errorInfo)
@@ -559,7 +547,7 @@ extension Task
559547 let totalCount = tasks. count
560548
561549 for task in tasks {
562- task. then { ( value: Value ) -> Void in
550+ task. onSuccess { ( value: Value ) -> Void in
563551
564552 synchronized ( self ) {
565553 completedCount++
@@ -571,7 +559,7 @@ extension Task
571559 }
572560 }
573561
574- } . catch { ( errorInfo: ErrorInfo ) -> Void in
562+ } . onFailure { ( errorInfo: ErrorInfo ) -> Void in
575563
576564 synchronized ( self ) {
577565 rejectedCount++
@@ -594,7 +582,7 @@ extension Task
594582 }
595583
596584 /// Returns new task which performs all given tasks and stores only fulfilled values.
597- /// This new task will NEVER be internally rejected (thus uncatchable from outside) .
585+ /// This new task will NEVER be internally rejected.
598586 public class func some( tasks: [ Task ] ) -> Task < BulkProgress , [ Value ] , Error >
599587 {
600588 return Task < BulkProgress , [ Value ] , Error > { ( progress, fulfill, _reject: _RejectHandler , configure) in
@@ -603,7 +591,7 @@ extension Task
603591 let totalCount = tasks. count
604592
605593 for task in tasks {
606- task. then { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Void in
594+ task. onComplete { ( value: Value ? , errorInfo: ErrorInfo ? ) -> Void in
607595
608596 synchronized ( self ) {
609597 completedCount++
0 commit comments