ConcurrentOperation

open class ConcurrentOperation : Operation

It allows asynchronous tasks, has a pause and resume states, can be easily added to a queue and can be created with a block.

  • Operation‘s execution block.

    Declaration

    Swift

    public var executionBlock: ((ConcurrentOperation) -> Void)?
  • Set the Operation as asynchronous.

    Declaration

    Swift

    override open var isAsynchronous: Bool { get }
  • Set if the Operation is executing.

    Declaration

    Swift

    override open var isExecuting: Bool { get }
  • Set if the Operation is finished.

    Declaration

    Swift

    override open var isFinished: Bool { get }
  • Operation progress, set it as many times as you like within the Operation execution. Useful for Queue Restoration.

    Declaration

    Swift

    open var progress: Int { get set }
  • You should use hasFailed if you want the retry feature. Set it to true if the Operation has failed, otherwise false. Default is false to avoid retries.

    Declaration

    Swift

    open var hasFailed: Bool
  • Maximum allowed retries. Default are 3 retries.

    Declaration

    Swift

    open var maximumRetries: Int
  • Current retry attempt.

    Declaration

    Swift

    open private(set) var currentAttempt: Int
  • Allows for manual retries. If set to true, retry() function must be manually called. Default is false to automatically retry.

    Declaration

    Swift

    open var manualRetry: Bool
  • Creates the Operation with an execution block.

    Declaration

    Swift

    public init(name: String? = nil, executionBlock: ((_ operation: ConcurrentOperation) -> Void)? = nil)

    Parameters

    name

    Operation name, useful for Queue Restoration. It must be unique.

    executionBlock

    Execution block.

  • Start the Operation.

    Declaration

    Swift

    override open func start()
  • Retry function. It only works if manualRetry property has been set to true.

    Declaration

    Swift

    open func retry()
  • Execute the Operation. If executionBlock is set, it will be executed and also finish() will be called.

    Declaration

    Swift

    open func execute()
  • Notify the completion of async task and hence the completion of the Operation. Must be called when the Operation is finished.

    Declaration

    Swift

    open func finish(_ hasFailed: Bool)

    Parameters

    hasFailed

    Set it to true if the Operation has failed, otherwise false.

  • Pause the current Operation, if it’s supported. Must be overridden by a subclass to get a custom pause action.

    Declaration

    Swift

    open func pause()
  • Resume the current Operation, if it’s supported. Must be overridden by a subclass to get a custom resume action.

    Declaration

    Swift

    open func resume()