Pause NSOperation

前端 未结 1 662
予麋鹿
予麋鹿 2021-02-04 17:38

I have NSOperationQueue with some NSOperations in it (NSInvocationOperations, in particular). This operations do some calculations and cha

相关标签:
1条回答
  • 2021-02-04 18:27

    The question is a bit vague, so it's hard to say without knowing all of the code in play. With that said, I may approach the problem by:

    Option 1. In your subclass of NSOperation, add your own atomic KVO property "isPaused". Within the operation itself, observe that property and handle accordingly if it ever changes.

    Option 2. Are you ever suspending the Operation Queue itself? If so, consider observing that property from within your operations, and each one independently can take action if that value changes.

    Option 3. Cancel all operations in the queue, and if the view appears again, just restart with new operations.

    Overall, though, there is no magic bullet for pausing operations already in progress. You'll have to bake your own solution. The damage shouldn't be too bad though.

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