NSOperation - Forcing an operation to wait others dynamically

后端 未结 7 1835
情话喂你
情话喂你 2020-12-12 21:59

I am trying to implement an operation queue and I have the following scenario:

NSOperation A
NSOperation B
NSOperation C
NSOperation D
NSOperationQueue queue         


        
相关标签:
7条回答
  • 2020-12-12 22:22

    One approach is to manage this from outside the operation classes ie. setup the operation dependencies between A/B/C/D correctly while creating them.

    Steps: (In the method that is creating these operations)

    1) Create Operation A

    2) If data provided by Operation B is not available, create Operation B, and make Operation A dependent on Operation B. ie. something like operationA.addDependency(operationB);

    3). repeat step 2 for C and D. (ie. B depends on C and C depends on D, if required)

    4) Add the operations to queue. The queue will execute based on the dependencies ie. D, C, B, A.

    0 讨论(0)
提交回复
热议问题