Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSOperations, dependencies and failed operations

I've started working with CloudKit and finally started using subclassed NSOperation for most of my async stuff.

How ever, I have two questions.

  1. How can I mark an operation as failed? That is, if operation A fails, I don't wan't its dependent operations to run. Can I just not mark it as isFinished? What happens to the unexecuted items already in the queue?

  2. What would be the recommended route to take if I would like something like a try, catch, finally. The end goal is to have one last operation that can display some UI with information of success or report errors back to the user?

like image 270
Johan Nordberg Avatar asked Nov 09 '22 05:11

Johan Nordberg


1 Answers

isFinished means your operations complete execution, you can cancel an operation but that means your operation is canceled and that could be done without even executing the operation and you can check that by calling isCanceled, if you want spefically failure and success flags after executing an NSOperation then in subclass add isFailure property and check in dependent operation before executing, and cancel that if isFailure is set to true.

You can add dependency on operation and check there status, and if all are successful just update UI on main thread or report and error.

Update You can keep and array of dependent operations and when on failure you can cancel those operations.

like image 76
Adnan Aftab Avatar answered Nov 14 '22 21:11

Adnan Aftab