Created
November 28, 2017 03:06
-
-
Save mahmudahsan/7db993c4d968af1cca1dabb6bfc5c02c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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