FBLPromise+Catch.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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>(CatchAdditions)
  16. typedef void (^FBLPromiseCatchWorkBlock)(NSError *error) NS_SWIFT_UNAVAILABLE("");
  17. /**
  18. Creates a pending promise which eventually gets resolved with same resolution as the receiver.
  19. If receiver is rejected, then `reject` block is executed asynchronously.
  20. @param reject A block to handle the error that receiver was rejected with.
  21. @return A new pending promise.
  22. */
  23. - (FBLPromise *)catch:(FBLPromiseCatchWorkBlock)reject NS_SWIFT_UNAVAILABLE("");
  24. /**
  25. Creates a pending promise which eventually gets resolved with same resolution as the receiver.
  26. If receiver is rejected, then `reject` block is executed asynchronously on the given queue.
  27. @param queue A queue to invoke the `reject` block on.
  28. @param reject A block to handle the error that receiver was rejected with.
  29. @return A new pending promise.
  30. */
  31. - (FBLPromise *)onQueue:(dispatch_queue_t)queue
  32. catch:(FBLPromiseCatchWorkBlock)reject NS_REFINED_FOR_SWIFT;
  33. @end
  34. /**
  35. Convenience dot-syntax wrappers for `FBLPromise` `catch` operators.
  36. Usage: promise.catch(^(NSError *error) { ... })
  37. */
  38. @interface FBLPromise<Value>(DotSyntax_CatchAdditions)
  39. - (FBLPromise* (^)(FBLPromiseCatchWorkBlock))catch FBL_PROMISES_DOT_SYNTAX NS_SWIFT_UNAVAILABLE("");
  40. - (FBLPromise* (^)(dispatch_queue_t, FBLPromiseCatchWorkBlock))catchOn FBL_PROMISES_DOT_SYNTAX
  41. NS_SWIFT_UNAVAILABLE("");
  42. @end
  43. NS_ASSUME_NONNULL_END