FBLPromise+Then.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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>(ThenAdditions)
  16. typedef id __nullable (^FBLPromiseThenWorkBlock)(Value __nullable value) NS_SWIFT_UNAVAILABLE("");
  17. /**
  18. Creates a pending promise which eventually gets resolved with resolution returned from `work`
  19. block: either value, error or another promise. The `work` block is executed asynchronously only
  20. when the receiver is fulfilled. If receiver is rejected, the returned promise is also rejected with
  21. the same error.
  22. @param work A block to handle the value that receiver was fulfilled with.
  23. @return A new pending promise to be resolved with resolution returned from the `work` block.
  24. */
  25. - (FBLPromise *)then:(FBLPromiseThenWorkBlock)work NS_SWIFT_UNAVAILABLE("");
  26. /**
  27. Creates a pending promise which eventually gets resolved with resolution returned from `work`
  28. block: either value, error or another promise. The `work` block is executed asynchronously when the
  29. receiver is fulfilled. If receiver is rejected, the returned promise is also rejected with the same
  30. error.
  31. @param queue A queue to invoke the `work` block on.
  32. @param work A block to handle the value that receiver was fulfilled with.
  33. @return A new pending promise to be resolved with resolution returned from the `work` block.
  34. */
  35. - (FBLPromise *)onQueue:(dispatch_queue_t)queue
  36. then:(FBLPromiseThenWorkBlock)work NS_REFINED_FOR_SWIFT;
  37. @end
  38. /**
  39. Convenience dot-syntax wrappers for `FBLPromise` `then` operators.
  40. Usage: promise.then(^id(id value) { ... })
  41. */
  42. @interface FBLPromise<Value>(DotSyntax_ThenAdditions)
  43. - (FBLPromise* (^)(FBLPromiseThenWorkBlock))then FBL_PROMISES_DOT_SYNTAX NS_SWIFT_UNAVAILABLE("");
  44. - (FBLPromise* (^)(dispatch_queue_t, FBLPromiseThenWorkBlock))thenOn FBL_PROMISES_DOT_SYNTAX
  45. NS_SWIFT_UNAVAILABLE("");
  46. @end
  47. NS_ASSUME_NONNULL_END