Memory

Operation & OperationQueue

Operations are an object-oriented way to encapsulate work that you want to perform asynchronously. Operations are designed to be used either in conjunction with an operation queue or by themselves Operations State An o...

J
Joynal Abedin
6
Operation & OperationQueue
Operations are an object-oriented way to encapsulate work that you want to perform asynchronously. Operations are designed to be used either in conjunction with an operation queue or by themselves

Operations State

An operation has a state machine that represents its lifecycle. There are several possible states that occur at various parts of this lifecycle:

  • When it’s been instantiated, it will transition to the isReady state.
  • When we invoked the start method, it will transition to the isExecutingstate.
  • When the task finished , it moves to isFinished
  • When task is in progress and you call cancel , then it will transition to the isCancelled state before moving onto the isFinished state
**There are mainly three ways to create operations
1. BlockOperation (Concrete Class)

2. NSInvocationOperation (Concrete Class)

3. Custom Operations

***BlockOperation (Concrete Class)

A class you use as-is to execute one or more block objects concurrently. Because it can execute more than one block, a block operation object operates using a group semantic; only when all of the associated blocks have finished executing is the operation itself considered finished.. In block operation you can take advantage of operation dependencies, KVO, notifications and cancelling.
Operation objects execute in a synchronous manner by default — that is, they perform their task in the thread that calls their start method.  
J

Written by Joynal Abedin

Passionate about technology, code, and sharing knowledge.

0 Comments

Leave a Comment