Is there a way to stop a concurrentPerform operation?
let count = arr.count
let group = DispatchGroup()
group.enter()
DispatchQueue.concurrentPerform(iterations: count, execute: { i in
if stop { group.leave(); return } // Crashes with EXC_BAD_INSTRUCTION
// ..
})
group.wait()
This crashes with EXC_BAD_INSTRUCTION
after a few iteration. Seems like the group.leave()
is not exiting the operation. How to exit cancel the operation? Basically, what I am trying to do is loop an array concurrently and break out of it if some condition is met, without using Objective-C bridge to use concurrent enumeration.