O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating and using a concurrent queue

A concurrent queue will execute the tasks in a FIFO order; however, the tasks will execute concurrently and finish in any order. Let's see how we would create and use a concurrent queue. The following line will create the concurrent queue that we will be using for this section and will also create an instance of the DoCalculations type that will be used to test the queue:

let cqueue = DispatchQueue(label: "cqueue.hoffman.jon",                            attributes:.concurrent) 
let calculation = DoCalculations() 

The first line will create a new dispatch queue that we will name cqueue, and the second line creates an instance of the DoCalculations type. Now let's see how we would use our concurrent queue by using the performCalculation() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required