简体   繁体   中英

Cancelling all operations on OperationQueue

When cancelling all operations in the queue, as the docs says, some operations could be still left in the queue, which is fine. But let's say that from 5 operations in queue with maxConcurrentOperationCount = 1 . This second operation is failing and then I call cancelAllOperations() . When I check the queue there is still one operation inside. In the app then I pull to refresh i want to repeat the process, but what about the previous operation left? I want to reuse the same queue. Any suggestions?

Cancelling isn't the thing that removes operations from a queue. The thing that triggers their removal is setting the operation's finished to true . Once the queue sees the finished moving to true it removes the operation from the queue. If an operation is still in the queue, maybe its finished wasn't set properly.

Well even setting isExecuting = false and isFinished = true the operations were still in the queue. What I did was re-initializing the queue again after cancelling the requests. In that way the operations are "deleted" and the queue is empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM