Jean-Luc Godard
Jean-Luc Godard

Reputation: 1883

sync and async status of Operation and OperationQueues

I am reading docs on OperationQueue.

I have this doubt, what is the sync and async status of the operation, BlockOperation and OperationQueue we are creating.

As I am understanding it, it will run as sync operation, but in case we want to run it in async manner we have to dispatch it it in async manner using dispatch.async.

Am I understanding it right?

Upvotes: 0

Views: 509

Answers (1)

juhan_h
juhan_h

Reputation: 4021

Synchronous operation will be seen as completed by OperationQueue when the block you submit to BlockOperation returns (or main method if you subclass Operation)

Asynchronous operation (that is returning true from its isAsynchronous property), must be marked as finished manually in a subclass of Operation by setting isFinished = true (you should also set isExecuting = false at the same time). This allows you to dispatch whatever work you need to do to a different queue by using Dispatch.async, but still keep the operation in OperationQueue. This is useful to build dependant operations or to allow only certain amount of operations to run in parallel.

Apple's Operation docs have good explanations for all of this.

Upvotes: 1

Related Questions