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
| let serial1 = DispatchQueue(label: "com.besher.serial1") | |
| let serial2 = DispatchQueue(label: "com.besher.serial2") | |
| serial1.async { | |
| for _ in 0..<5 { print("🔵") } | |
| } | |
| serial2.async { | |
| for _ in 0..<5 { print("🔴") } | |
| } |
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
| let imageProcessingQueue = DispatchQueue(label: "com.besher.image-processing") | |
| func processImageAsync(data: Data, completion: @escaping (UIImage?) -> Void) { | |
| guard let image = UIImage(data: data) else { | |
| completion(nil) | |
| return | |
| } | |
| imageProcessingQueue.async { | |
| let processedImage = self.upscaleAndFilter(image: image) |
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
| let imageProcessingQueue = DispatchQueue(label: "com.besher.image-processing") | |
| func processImageAsync(data: Data) -> UIImage? { | |
| guard let image = UIImage(data: data) else { return nil } | |
| imageProcessingQueue.async { | |
| let processedImage = upscaleAndFilter(image: image) | |
| return processedImage | |
| } | |
| } |
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
| DispatchQueue.global().async { | |
| print("Inside") | |
| } | |
| print("Outside") | |
| // Potential console output (based on QoS): | |
| // Outside | |
| // Inside |
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
| DispatchQueue.global().sync { | |
| print("Inside") | |
| } | |
| print("Outside") | |
| // Console output: | |
| // Inside | |
| // Outside |
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
| DispatchQueue.global().async { | |
| for i in 0..<10 { | |
| print(i) | |
| } | |
| for _ in 0..<10 { | |
| print("🔵") | |
| } | |
| for _ in 0..<10 { |
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
| let item = DispatchWorkItem(qos: .utility) { | |
| print("Work item to be executed later") | |
| } |
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
| DispatchQueue.global().async { | |
| print("Anonymous closure") | |
| } |
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
| let concurrent = DispatchQueue(label: "com.besher.serial-queue", attributes: .concurrent) | |
| concurrent.sync { | |
| print("Private concurrent queue") | |
| } |
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
| let serial = DispatchQueue(label: "com.besher.serial-queue") | |
| serial.async { | |
| print("Private serial queue") | |
| } |