FBLPromise+Recover.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. Copyright 2018 Google Inc. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at:
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #import "FBLPromise+Recover.h"
  14. #import "FBLPromisePrivate.h"
  15. @implementation FBLPromise (RecoverAdditions)
  16. - (FBLPromise *)recover:(FBLPromiseRecoverWorkBlock)recovery {
  17. return [self onQueue:FBLPromise.defaultDispatchQueue recover:recovery];
  18. }
  19. - (FBLPromise *)onQueue:(dispatch_queue_t)queue recover:(FBLPromiseRecoverWorkBlock)recovery {
  20. NSParameterAssert(queue);
  21. NSParameterAssert(recovery);
  22. return [self chainOnQueue:queue
  23. chainedFulfill:nil
  24. chainedReject:^id(NSError *error) {
  25. return recovery(error);
  26. }];
  27. }
  28. @end
  29. @implementation FBLPromise (DotSyntax_RecoverAdditions)
  30. - (FBLPromise * (^)(FBLPromiseRecoverWorkBlock))recover {
  31. return ^(FBLPromiseRecoverWorkBlock recovery) {
  32. return [self recover:recovery];
  33. };
  34. }
  35. - (FBLPromise * (^)(dispatch_queue_t, FBLPromiseRecoverWorkBlock))recoverOn {
  36. return ^(dispatch_queue_t queue, FBLPromiseRecoverWorkBlock recovery) {
  37. return [self onQueue:queue recover:recovery];
  38. };
  39. }
  40. @end