FSTDispatchQueue.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. NS_ASSUME_NONNULL_BEGIN
  18. @interface FSTDispatchQueue : NSObject
  19. /** Creates and returns an FSTDispatchQueue wrapping the specified dispatch_queue_t. */
  20. + (instancetype)queueWith:(dispatch_queue_t)dispatchQueue;
  21. - (instancetype)init __attribute__((unavailable("Use static constructor method.")));
  22. /**
  23. * Asserts that we are already running on this queue (actually, we can only verify that the
  24. * queue's label is the same, but hopefully that's good enough.)
  25. */
  26. - (void)verifyIsCurrentQueue;
  27. /**
  28. * Same as dispatch_async() except it asserts that we're not already on the queue, since this
  29. * generally indicates a bug (and can lead to re-ordering of operations, etc).
  30. *
  31. * @param block The block to run.
  32. */
  33. - (void)dispatchAsync:(void (^)())block;
  34. /**
  35. * Unlike dispatchAsync: this method does not require you to dispatch to a different queue than
  36. * the current one (thus it is equivalent to a raw dispatch_async()).
  37. *
  38. * This is useful, e.g. for dispatching to the user's queue directly from user API call (in which
  39. * case we don't know if we're already on the user's queue or not).
  40. *
  41. * @param block The block to run.
  42. */
  43. - (void)dispatchAsyncAllowingSameQueue:(void (^)())block;
  44. /** The underlying wrapped dispatch_queue_t */
  45. @property(nonatomic, strong, readonly) dispatch_queue_t queue;
  46. @end
  47. NS_ASSUME_NONNULL_END