alibaba / coobjc

coobjc provides coroutine support for Objective-C and Swift. We added await method、generator and actor model like C#、Javascript and Kotlin. For convenience, we added coroutine categories for some Foundation and UIKit API in cokit framework like NSFileManager, JSON, NSData, UIImage etc. We also add tuple support in coobjc.

Home Page:https://github.com/alibaba/coobjc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thread 2: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

EvoIos opened this issue · comments

使用 concurrent queue 做promis函数,崩溃了

Context and Description

Environment Details

  • coobjc version: coswift 1.1.2
  • iOS version: iOS 12
  • Xcode version: 10.1
  • Other informations:

code

class CoobjcDemoViewController: BaseViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        co_launch {
            let result = try await(closure: { () -> Promise<String> in
                self.asyncFunc(name: "Han MeiMei")
            })
            switch result {
            case .fulfilled(let name):
                print(name)
            case .rejected(let error):
                print(error)
            }
        }
    }
    
    func asyncFunc(name: String) -> Promise<String> {
        let promise = Promise<String>()
        DispatchQueue.init(label: "concurrent queue", attributes: .concurrent).async {
            print("current: \(name), thread: \(Thread.current)")
            promise.fulfill(value: "Li Lei")
        }
        promise.onCancel { (_) in
            
        }
        return promise
    }
}

多次�快速进入这个VC的时候,就会崩溃掉

method call stacks

image

image

It's indeed a problem, we designed require serial queue for now.

@NianJi

serial queue has the same problem

eg:

  • source code
    override func viewDidLoad() {
        super.viewDidLoad()
        co_launch {
            let result = try await(closure: { () -> Promise<String> in
                self.asyncFunc(name: "Han MeiMei")
            })
            switch result {
            case .fulfilled(let name):
                print(name)
            case .rejected(let error):
                print(error)
            }
        }
    }
    
    func asyncFunc(name: String) -> Promise<String> {
        let promise = Promise<String>()
        DispatchQueue.init(label: "serial queue").async {
            print("serial: \(name), thread: \(Thread.current)")
            promise.fulfill(value: "Li Lei")
        }
        promise.onCancel { (_) in
            
        }
        return promise
    }
  • crash at

image

call stack

image