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.

60 lines
2.1 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>(ValidateAdditions)
  16. typedef BOOL (^FBLPromiseValidateWorkBlock)(Value __nullable value) NS_SWIFT_UNAVAILABLE("");
  17. /**
  18. Validates a fulfilled value or rejects the value if it can not be validated.
  19. @param predicate An expression to validate.
  20. @return A new pending promise that gets either resolved with same resolution as the receiver or
  21. rejected with `FBLPromiseErrorCodeValidationFailure` error code in `FBLPromiseErrorDomain`.
  22. */
  23. - (FBLPromise *)validate:(FBLPromiseValidateWorkBlock)predicate NS_SWIFT_UNAVAILABLE("");
  24. /**
  25. Validates a fulfilled value or rejects the value if it can not be validated.
  26. @param queue A queue to dispatch on.
  27. @param predicate An expression to validate.
  28. @return A new pending promise that gets either resolved with same resolution as the receiver or
  29. rejected with `FBLPromiseErrorCodeValidationFailure` error code in `FBLPromiseErrorDomain`.
  30. */
  31. - (FBLPromise *)onQueue:(dispatch_queue_t)queue
  32. validate:(FBLPromiseValidateWorkBlock)predicate NS_REFINED_FOR_SWIFT;
  33. @end
  34. /**
  35. Convenience dot-syntax wrappers for `FBLPromise` `validate` operators.
  36. Usage: promise.validate(^BOOL(id value) { ... })
  37. */
  38. @interface FBLPromise<Value>(DotSyntax_ValidateAdditions)
  39. - (FBLPromise * (^)(FBLPromiseValidateWorkBlock))validate FBL_PROMISES_DOT_SYNTAX
  40. NS_SWIFT_UNAVAILABLE("");
  41. - (FBLPromise * (^)(dispatch_queue_t, FBLPromiseValidateWorkBlock))validateOn
  42. FBL_PROMISES_DOT_SYNTAX NS_SWIFT_UNAVAILABLE("");
  43. @end
  44. NS_ASSUME_NONNULL_END