FBLPromise+Async.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>(AsyncAdditions)
  16. typedef void (^FBLPromiseFulfillBlock)(Value __nullable value) NS_SWIFT_UNAVAILABLE("");
  17. typedef void (^FBLPromiseRejectBlock)(NSError *error) NS_SWIFT_UNAVAILABLE("");
  18. typedef void (^FBLPromiseAsyncWorkBlock)(FBLPromiseFulfillBlock fulfill,
  19. FBLPromiseRejectBlock reject) NS_SWIFT_UNAVAILABLE("");
  20. /**
  21. Creates a pending promise and executes `work` block asynchronously.
  22. @param work A block to perform any operations needed to resolve the promise.
  23. @return A new pending promise.
  24. */
  25. + (instancetype)async:(FBLPromiseAsyncWorkBlock)work NS_SWIFT_UNAVAILABLE("");
  26. /**
  27. Creates a pending promise and executes `work` block asynchronously on the given queue.
  28. @param queue A queue to invoke the `work` block on.
  29. @param work A block to perform any operations needed to resolve the promise.
  30. @return A new pending promise.
  31. */
  32. + (instancetype)onQueue:(dispatch_queue_t)queue
  33. async:(FBLPromiseAsyncWorkBlock)work NS_REFINED_FOR_SWIFT;
  34. @end
  35. /**
  36. Convenience dot-syntax wrappers for `FBLPromise` `async` operators.
  37. Usage: FBLPromise.async(^(FBLPromiseFulfillBlock fulfill, FBLPromiseRejectBlock reject) { ... })
  38. */
  39. @interface FBLPromise<Value>(DotSyntax_AsyncAdditions)
  40. + (FBLPromise* (^)(FBLPromiseAsyncWorkBlock))async FBL_PROMISES_DOT_SYNTAX NS_SWIFT_UNAVAILABLE("");
  41. + (FBLPromise* (^)(dispatch_queue_t, FBLPromiseAsyncWorkBlock))asyncOn FBL_PROMISES_DOT_SYNTAX
  42. NS_SWIFT_UNAVAILABLE("");
  43. @end
  44. NS_ASSUME_NONNULL_END