Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import Foundation
  2. import FutureKit
  3.  
  4. extension Future {
  5. public final func onSuccessTry<__Type>(executor: Executor, block:(result:T) throws -> __Type) -> Future<__Type> {
  6. return onSuccess(executor) { result -> Completion<__Type> in
  7. do {
  8. let blockResult = try block(result: result)
  9. return .Success(blockResult)
  10. }
  11. catch let error {
  12. return .Fail(error)
  13. }
  14. }
  15. }
  16.  
  17. public final func onSuccessTry<__Type>(block:(result:T) throws -> __Type) -> Future<__Type> {
  18. return onSuccess { result -> Completion<__Type> in
  19. do {
  20. let blockResult = try block(result: result)
  21. return .Success(blockResult)
  22. }
  23. catch let error {
  24. return .Fail(error)
  25. }
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement