GIDCallbackQueue.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2021 Google LLC
  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. NS_ASSUME_NONNULL_BEGIN
  18. @class GIDCallbackQueue;
  19. // The block type of callbacks in the queue.
  20. typedef void (^GIDCallbackQueueCallback)(void);
  21. // The class handles a queue for callbacks for asynchronous operations.
  22. // The queue starts in a ready state. Call |wait| and |next| to mark the
  23. // start and end of asynchronous operations.
  24. @interface GIDCallbackQueue : NSObject
  25. // Marks the start of an asynchronous operation. Any remaining callbacks will
  26. // not be called until |next| is called. The queue object will be retained while
  27. // some asynchronous operation is pending.
  28. - (void)wait;
  29. // Marks the end of an asynchronous operation. If no more operation remain,
  30. // all remaining callbacks are called in the order they are added. Note that
  31. // some earlier callbackes can start asynchronous operations themselves, thus
  32. // blocking later callbacks until they are finished.
  33. - (void)next;
  34. // Resets the callback queue to the ready state and removes all callbacks.
  35. - (void)reset;
  36. // Adds a callback to the end of the callback queue. Callbacks added later will
  37. // only be called when both the callbacks added eariler and the asynchronous
  38. // operations they started if any are finished.
  39. - (void)addCallback:(GIDCallbackQueueCallback)callback;
  40. @end
  41. NS_ASSUME_NONNULL_END