Code snippet:
———————————————————————
let operation1 : NSBlockOperation = NSBlockOperation (block: {
sleep(1)
print("Opertion1")
})
let operation2 : NSBlockOperation = NSBlockOperation (block: {
sleep(1)
print("Opertion2”)
})
var operations = [NSOperation]()
operations.append(operation1)
operations.append(operation2)
let queue = NSOperationQueue()
queue.maxConcurrentOperationCount = 1
queue.addOperations(operations, waitUntilFinished: true)
————————————————————————
The above code snippet of adding operations to an operation queue and executing with the property ‘maxConcurrentOperationCount = 1’ fails while executing the above with the OpenSource Foundation and libDispatch of MAC inside Xcode.
The error I am seeing is:
fatal error: unexpectedly found nil while unwrapping an Optional value
Stack trace points to: attr = DISPATCH_QUEUE_SERIAL
which implies that the libDispatch macro is coming as nil during the creation of the serial queue using libDispatch in the file NSOperationQueue
The same test-case passes on OSx.
When I do not restrict the serial operation i.e. I remove ‘ queue.maxConcurrentOperationCount = 1’ , test case executes successfully.
Setting it to a different value other than 1 also causes no problems.
Am I doing something wrong with the API. If I set the property ‘ queue.maxConcurrentOperationCount = 1’ after adding operations to the queue, then the problem does not occur. But then this restricts me to control the operation execution to be serial. So, I expect the above snippet to work on OpenSource as well. Any thoughts on this?
_______________________________________________ swift-corelibs-dev mailing list swift-corelibs-dev@swift.org https://lists.swift.org/mailman/listinfo/swift-corelibs-dev