FBLPromise+Recover.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.h"
  14. NS_ASSUME_NONNULL_BEGIN
  15. @interface FBLPromise<Value>(RecoverAdditions)
  16. typedef id __nullable (^FBLPromiseRecoverWorkBlock)(NSError *error) NS_SWIFT_UNAVAILABLE("");
  17. /**
  18. Provides a new promise to recover in case the receiver gets rejected.
  19. @param recovery A block to handle the error that the receiver was rejected with.
  20. @return A new pending promise to use instead of the rejected one that gets resolved with resolution
  21. returned from `recovery` block.
  22. */
  23. - (FBLPromise *)recover:(FBLPromiseRecoverWorkBlock)recovery NS_SWIFT_UNAVAILABLE("");
  24. /**
  25. Provides a new promise to recover in case the receiver gets rejected.
  26. @param queue A queue to dispatch on.
  27. @param recovery A block to handle the error that the receiver was rejected with.
  28. @return A new pending promise to use instead of the rejected one that gets resolved with resolution
  29. returned from `recovery` block.
  30. */
  31. - (FBLPromise *)onQueue:(dispatch_queue_t)queue
  32. recover:(FBLPromiseRecoverWorkBlock)recovery NS_REFINED_FOR_SWIFT;
  33. @end
  34. /**
  35. Convenience dot-syntax wrappers for `FBLPromise` `recover` operators.
  36. Usage: promise.recover(^id(NSError *error) {...})
  37. */
  38. @interface FBLPromise<Value>(DotSyntax_RecoverAdditions)
  39. - (FBLPromise * (^)(FBLPromiseRecoverWorkBlock))recover FBL_PROMISES_DOT_SYNTAX
  40. NS_SWIFT_UNAVAILABLE("");
  41. - (FBLPromise * (^)(dispatch_queue_t, FBLPromiseRecoverWorkBlock))recoverOn FBL_PROMISES_DOT_SYNTAX
  42. NS_SWIFT_UNAVAILABLE("");
  43. @end
  44. NS_ASSUME_NONNULL_END