Skip to content

Instantly share code, notes, and snippets.

@mahmudahsan
Created November 28, 2017 03:06
Show Gist options
  • Save mahmudahsan/7db993c4d968af1cca1dabb6bfc5c02c to your computer and use it in GitHub Desktop.
Save mahmudahsan/7db993c4d968af1cca1dabb6bfc5c02c to your computer and use it in GitHub Desktop.
import UIKit
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let workingQueue = DispatchQueue(label: "net.ithinkdiff.app", attributes: .concurrent)
let globalQueue = DispatchQueue.global()
let defaultGroup = DispatchGroup() //create a new group
func multiplication(_ num: (Int, Int)) -> Int{
sleep(1) //to make the method slower
return num.0 * num.1
}
let groupOfNumbers = [(1, 1), (5, 2), (3, 4)]
for pair in groupOfNumbers{
//group of task assigning in working queue
workingQueue.async(group: defaultGroup){
let result = multiplication(pair)
print("Result: \(result)")
}
}
//notification
defaultGroup.notify(queue: globalQueue){
print("Multiplication Done!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment