FIRInstallationsSingleOperationPromiseCache.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. @class FBLPromise<ValueType>;
  18. NS_ASSUME_NONNULL_BEGIN
  19. /**
  20. * The class makes sure the a single operation (represented by a promise) is performed at a time. If
  21. * there is an ongoing operation, then its existing corresponding promise will be returned instead
  22. * of starting a new operation.
  23. */
  24. @interface FIRInstallationsSingleOperationPromiseCache<__covariant ResultType> : NSObject
  25. - (instancetype)init NS_UNAVAILABLE;
  26. /**
  27. * The designated initializer.
  28. * @param newOperationHandler The block that must return a new promise representing the
  29. * single-at-a-time operation. The promise should be fulfilled when the operation is completed. The
  30. * factory block will be used to create a new promise when needed.
  31. */
  32. - (instancetype)initWithNewOperationHandler:
  33. (FBLPromise<ResultType> *_Nonnull (^)(void))newOperationHandler NS_DESIGNATED_INITIALIZER;
  34. /**
  35. * Creates a new promise or returns an existing pending one.
  36. * @return Returns and existing pending promise if exists. If the pending promise does not exist
  37. * then a new one will be created using the `factory` block passed in the initializer. Once the
  38. * pending promise gets resolved, it is removed, so calling the method again will lead to creating
  39. * and caching another promise.
  40. */
  41. - (FBLPromise<ResultType> *)getExistingPendingOrCreateNewPromise;
  42. /**
  43. * Returns an existing pending promise or `nil`.
  44. * @return Returns an existing pending promise if there is one or `nil` otherwise.
  45. */
  46. - (nullable FBLPromise<ResultType> *)getExistingPendingPromise;
  47. @end
  48. NS_ASSUME_NONNULL_END