Hi Team,
We intend to create a custom serial dispatch queue targetting a global queue.
let serialQueue = DispatchQueue(label: "corecomm.tallyworld.serial", target: DispatchQueue.global(qos: .default))
The documentation for DispatchQueue init does not show any minimum OS versions. BUT DispatchSerialQueue init does show iOS 17.0+ iPadOS 17.0+ Mac Catalyst macOS 14.0+ tvOS 17.0+ visionOS watchOS 10.0+.
Does that mean - I will not be able to create a custom serial dispatch queue below iOS 17?
We intend to use it for our communication subsystem - to associate it and start [NWConnection]
OK, cool. Then I have some good news (-:
Network framework doesn’t require you to use a serial queue. The parameter for, say, connection.start(queue:)
is of type DispatchQueue
.
Now, using anything other than a serial queue is, of course, bananas. For a concrete example of where using a concurrent queue with Network framework caused problems, see this thread. However, the important point is that this desire to use a serial queue isn’t encoded in the type system. That is, you’re not required to use DispatchSerialQueue
.
Given that, it’s fine to create a DispatchQueue
for this work as long as the underlying queue is serial. So, for example, this code compiles:
let connection = NWConnection(host: "example", port: 443, using: .tls)
let queue = DispatchQueue(label: "network-queue", target: nil)
connection.start(queue: queue)
even with the deployment target set to macOS 10.14, that is, the OS release where Network framework was introduced.
And if you want to set a target queue for your serial queue, you can do that using the target
parameter that I’ve left nil
in this example.
ps Your example does this:
let serialQueue = DispatchQueue(…, target: DispatchQueue.global(qos: .default))
That’s weird because the default global concurrent queue is the default target for a serial queue. IMO you should only set a target if it’s something other than this default.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"