PSOperations icon indicating copy to clipboard operation
PSOperations copied to clipboard

GroupOperation Finished not called when adding operation

Open agiguere opened this issue 8 years ago • 2 comments

I notice that in a GroupOperation, if you generate a new operation in the method

operationDidFinish(_ operation: Foundation.Operation, withErrors errors: [NSError])

using addOperation

the finished(_ errors: [NSError]) is not called

example: GroupOperation that contains OperationA & OperationB

when OperationB finish, you want to generate OperationC on a particular condition

OperationC will be execute successfully and the block observer will be called correctly, however the GroupOperation won't called it's finish method

Is that a bug ?

thanks

agiguere avatar Feb 06 '17 17:02 agiguere

Just found something, I was generating 2 operations using the AddOperation, if I only generate one, the finished will be called

as stated in the example: when OperationB finish I am generating 2 independent operations (C & D) using the AddOperation, by doing this it looks like the BlockOberser finish completion handler is not called and the finish method also

Workaround: Generate Operation C and in the same method operationDidFinish(_ operation: Foundation.Operation, withErrors errors: [NSError])

wait for it to finish and generate OperationD and it will works

ALEX

agiguere avatar Feb 06 '17 18:02 agiguere

@agiguere Are you saying before you would do something like this (and it wasn't working)?

func operationDidFinish(_ operation: Foundation.Operation, withErrors errors: [NSError]) {
    if operation === operationB {
         addOperation(OperationC())
         addOperation(OperationD())
    }
}

and now you're doing this (and it is working)?

func operationDidFinish(_ operation: Foundation.Operation, withErrors errors: [NSError]) {
    if operation === operationB {
         addOperation(OperationC())
    } else if operation === operationC {
         addOperation(OperationD())
    }
}

Asking for clarification because I'm running into similar issues.

jjatie avatar Nov 27 '18 12:11 jjatie