FSTWriteGroupTracker.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright 2017 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 FSTWriteGroup;
  18. NS_ASSUME_NONNULL_BEGIN
  19. /**
  20. * Helper class for FSTPersistence implementations to create WriteGroups and verify internal
  21. * contracts are maintained:
  22. * 1. Can't create a group when an uncommitted group exists (no nesting).
  23. * 2. Can't commit a group that differs from the last created one.
  24. */
  25. @interface FSTWriteGroupTracker : NSObject
  26. /** Creates and returns an FSTWriteGroupTracker instance. */
  27. + (instancetype)tracker;
  28. /**
  29. * Verifies there's no active group already and then creates a new group and stores it for later
  30. * validation with `endGroup`.
  31. */
  32. - (FSTWriteGroup *)startGroupWithAction:(NSString *)action;
  33. /** Ends a group previously started with `startGroupWithAction`. */
  34. - (void)endGroup:(FSTWriteGroup *)group;
  35. @end
  36. NS_ASSUME_NONNULL_END