You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.3 KiB

5 years ago
  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>(RaceAdditions)
  16. /**
  17. Wait until any of the given promises are fulfilled.
  18. If one of the promises is rejected, then the returned promise is rejected with same error.
  19. If any other arbitrary value or `NSError` appears in the array instead of `FBLPromise`,
  20. it's implicitly considered a pre-fulfilled or pre-rejected `FBLPromise` correspondingly.
  21. @param promises Promises to wait for.
  22. @return A new pending promise to be resolved with the same resolution as the first promise, among
  23. the given ones, which was resolved.
  24. */
  25. + (instancetype)race:(NSArray *)promises NS_SWIFT_UNAVAILABLE("");
  26. /**
  27. Wait until any of the given promises are fulfilled.
  28. If one of the promises is rejected, then the returned promise is rejected with same error.
  29. If any other arbitrary value or `NSError` appears in the array instead of `FBLPromise`,
  30. it's implicitly considered a pre-fulfilled or pre-rejected `FBLPromise` correspondingly.
  31. @param queue A queue to dispatch on.
  32. @param promises Promises to wait for.
  33. @return A new pending promise to be resolved with the same resolution as the first promise, among
  34. the given ones, which was resolved.
  35. */
  36. + (instancetype)onQueue:(dispatch_queue_t)queue race:(NSArray *)promises NS_REFINED_FOR_SWIFT;
  37. @end
  38. /**
  39. Convenience dot-syntax wrappers for `FBLPromise` `race` operators.
  40. Usage: FBLPromise.race(@[ ... ])
  41. */
  42. @interface FBLPromise<Value>(DotSyntax_RaceAdditions)
  43. + (FBLPromise * (^)(NSArray *))race FBL_PROMISES_DOT_SYNTAX NS_SWIFT_UNAVAILABLE("");
  44. + (FBLPromise * (^)(dispatch_queue_t, NSArray *))raceOn FBL_PROMISES_DOT_SYNTAX
  45. NS_SWIFT_UNAVAILABLE("");
  46. @end
  47. NS_ASSUME_NONNULL_END