操作进行了isFinished = YES而不被它所在的队列启动 [英] Operation went isFinished=YES without being started by the queue it is in

查看:111
本文介绍了操作进行了isFinished = YES而不被它所在的队列启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 有一个异步操作子类
  • 将此操作添加到队列中.
  • 我在开始之前取消了该操作.

SomeOperation went isFinished=YES without being started by the queue it is in

  1. 这是可以忽略的事情还是严重的事情?
  2. 如何解决这个问题?
  3. 最后提供的解决方法/解决方案有效吗?

代码:

public class SomeOperation : AsyncOperation {

    //MARK: Start

    public override func start() {

        isExecuting = true

        guard !isCancelled else {
            markAsCompleted() //isExecuting = false, isFinished = true
            return
        }

        doSomethingAsynchronously { [weak self] in

            self?.markAsCompleted() //isExecuting = false, isFinished = true
        }
    }

    //MARK: Cancel

    public override func cancel() {

        super.cancel()
        markAsCompleted() //isExecuting = false, isFinished = true
    }
}

添加到队列并取消:

//someOperation is a property in a class
if let someOperation = someOperation {
    queue.addOperation(someOperation)
}

//Based on some condition cancelling it
someOperation?.cancel()

这有效吗?

public override func cancel() {

    isExecuting = true //Just in case the operation was cancelled before starting

    super.cancel()
    markAsCompleted()
}

注意:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆