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.

69 lines
2.9 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>(AnyAdditions)
  16. /**
  17. Waits until all of the given promises are either fulfilled or rejected.
  18. If all promises are rejected, then the returned promise is rejected with same error
  19. as the last one rejected.
  20. If at least one of the promises is fulfilled, the resulting promise is fulfilled with an array of
  21. values or `NSErrors`, matching the original order of fulfilled or rejected promises respectively.
  22. If any other arbitrary value or `NSError` appears in the array instead of `FBLPromise`,
  23. it's implicitly considered a pre-fulfilled or pre-rejected `FBLPromise` correspondingly.
  24. Promises resolved with `nil` become `NSNull` instances in the resulting array.
  25. @param promises Promises to wait for.
  26. @return Promise of array containing the values or `NSError`s of input promises in the same order.
  27. */
  28. + (FBLPromise<NSArray *> *)any:(NSArray *)promises NS_SWIFT_UNAVAILABLE("");
  29. /**
  30. Waits until all of the given promises are either fulfilled or rejected.
  31. If all promises are rejected, then the returned promise is rejected with same error
  32. as the last one rejected.
  33. If at least one of the promises is fulfilled, the resulting promise is fulfilled with an array of
  34. values or `NSError`s, matching the original order of fulfilled or rejected promises respectively.
  35. If any other arbitrary value or `NSError` appears in the array instead of `FBLPromise`,
  36. it's implicitly considered a pre-fulfilled or pre-rejected `FBLPromise` correspondingly.
  37. Promises resolved with `nil` become `NSNull` instances in the resulting array.
  38. @param queue A queue to dispatch on.
  39. @param promises Promises to wait for.
  40. @return Promise of array containing the values or `NSError`s of input promises in the same order.
  41. */
  42. + (FBLPromise<NSArray *> *)onQueue:(dispatch_queue_t)queue
  43. any:(NSArray *)promises NS_REFINED_FOR_SWIFT;
  44. @end
  45. /**
  46. Convenience dot-syntax wrappers for `FBLPromise` `any` operators.
  47. Usage: FBLPromise.any(@[ ... ])
  48. */
  49. @interface FBLPromise<Value>(DotSyntax_AnyAdditions)
  50. + (FBLPromise<NSArray *> * (^)(NSArray *))any FBL_PROMISES_DOT_SYNTAX NS_SWIFT_UNAVAILABLE("");
  51. + (FBLPromise<NSArray *> * (^)(dispatch_queue_t, NSArray *))anyOn FBL_PROMISES_DOT_SYNTAX
  52. NS_SWIFT_UNAVAILABLE("");
  53. @end
  54. NS_ASSUME_NONNULL_END