PINOperationQueue.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // PINOperationQueue.h
  3. // Pods
  4. //
  5. // Created by Garrett Moon on 8/23/16.
  6. //
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "PINOperationTypes.h"
  10. #import "PINOperationMacros.h"
  11. NS_ASSUME_NONNULL_BEGIN
  12. typedef void(^PINOperationBlock)(id _Nullable data);
  13. typedef _Nullable id(^PINOperationDataCoalescingBlock)(id _Nullable existingData, id _Nullable newData);
  14. @protocol PINOperationReference;
  15. PINOP_SUBCLASSING_RESTRICTED
  16. @interface PINOperationQueue : NSObject
  17. - (instancetype)init NS_UNAVAILABLE;
  18. - (instancetype)initWithMaxConcurrentOperations:(NSUInteger)maxConcurrentOperations;
  19. - (instancetype)initWithMaxConcurrentOperations:(NSUInteger)maxConcurrentOperations concurrentQueue:(dispatch_queue_t)concurrentQueue NS_DESIGNATED_INITIALIZER;
  20. + (instancetype)sharedOperationQueue;
  21. - (id <PINOperationReference>)addOperation:(dispatch_block_t)operation;
  22. - (id <PINOperationReference>)addOperation:(dispatch_block_t)operation withPriority:(PINOperationQueuePriority)priority;
  23. - (id <PINOperationReference>)addOperation:(PINOperationBlock)operation
  24. withPriority:(PINOperationQueuePriority)priority
  25. identifier:(NSString *)identifier
  26. coalescingData:(nullable id)coalescingData
  27. dataCoalescingBlock:(nullable PINOperationDataCoalescingBlock)dataCoalescingBlock
  28. completion:(nullable dispatch_block_t)completion;
  29. @property (assign) NSUInteger maxConcurrentOperations;
  30. /**
  31. * Marks the operation as cancelled
  32. */
  33. - (BOOL)cancelOperation:(id <PINOperationReference>)operationReference;
  34. /**
  35. * Cancels all queued operations
  36. */
  37. - (void)cancelAllOperations;
  38. /*
  39. * Blocks the current thread until all of the receiver’s queued and executing operations finish executing.
  40. *
  41. * @discussion When called, this method blocks the current thread and waits for the receiver’s current and queued
  42. * operations to finish executing. While the current thread is blocked, the receiver continues to launch already
  43. * queued operations and monitor those that are executing.
  44. *
  45. * @warning This should never be called from within an operation submitted to the PINOperationQueue as this will result
  46. * in a deadlock.
  47. */
  48. - (void)waitUntilAllOperationsAreFinished;
  49. - (void)setOperationPriority:(PINOperationQueuePriority)priority withReference:(id <PINOperationReference>)reference;
  50. @end
  51. @protocol PINOperationReference <NSObject>
  52. @end
  53. NS_ASSUME_NONNULL_END