Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is exactly what <code>NSOperation</code> is designed for. Dispatch queues are much lower-level handlers, and you'd have to construct many of the pieces you need for this. You can of course do that (<code>NSOperationQueue</code> is built on top of GCD), but you'd be reinventing <code>NSOperation</code>.</p> <p>You can handle <code>NSOperation</code> two ways for the most part. If it's simple, you can just create an <code>NSBlockOperation</code>. If it's a bit more complex, you can subclass <code>NSOperation</code> and override the <code>main</code> method to do what you want.</p> <p>There are several ways to cancel all the other operations. You could have a separate operation queue per group. Then you can easily call <code>cancelAllOperations</code> to shut down everything. Or you could have a separate controller that knows the list of related operations and it could call <code>cancel</code> on them.</p> <p>Remember that "cancel" just means "don't schedule if it hasn't stared, and set <code>isCancelled</code> if it has." It doesn't abort a running operation. If you want to abort a running operation, the operation needs to periodically check <code>isCancelled</code>.</p> <p>You typically should limit the number of concurrent operations the queue will run. Use <code>setMaximimumConcurrentOperationCount:</code>.</p> <p>There are two ways to determine that all the operations are finished. You can make an extra operation (usually a <code>BlockOperation</code>) and use <code>addDependency:</code> to make it depend on all the other operations. That's a nice asynchronous solution. If you can handle a synchronous solution, then you can use <code>waitUntilAllOperationsAreFinished</code>. I typically prefer the former.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload