diff --git a/README.md b/README.md index 8992ea1..2abcdae 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ The [Swift Package Manager](https://swift.org/package-manager/) is a tool for ma ```swift dependencies: [ - .package(url: "https://github.com/omaralbeik/M3UKit.git", from: "0.5.2") + .package(url: "https://github.com/omaralbeik/M3UKit.git", from: "0.5.3") ] ``` @@ -121,7 +121,7 @@ $ swift build To integrate M3UKit into your Xcode project using [CocoaPods](https://cocoapods.org), specify it in your Podfile: ```rb -pod 'M3UKit', :git => 'https://github.com/omaralbeik/M3UKit.git', :tag => '0.5.2' +pod 'M3UKit', :git => 'https://github.com/omaralbeik/M3UKit.git', :tag => '0.5.3' ``` ### Carthage @@ -129,7 +129,7 @@ pod 'M3UKit', :git => 'https://github.com/omaralbeik/M3UKit.git', :tag => '0.5.2 To integrate M3UKit into your Xcode project using [Carthage](https://github.com/Carthage/Carthage), specify it in your Cartfile: ``` -github "omaralbeik/M3UKit" ~> 0.5.2 +github "omaralbeik/M3UKit" ~> 0.5.3 ``` ### Manually diff --git a/Sources/M3UKit/Parsers/PlaylistParser.swift b/Sources/M3UKit/Parsers/PlaylistParser.swift index 21b874d..74c8eea 100644 --- a/Sources/M3UKit/Parsers/PlaylistParser.swift +++ b/Sources/M3UKit/Parsers/PlaylistParser.swift @@ -124,21 +124,23 @@ public final class PlaylistParser: Parser { /// Parse a playlist on a queue with a completion handler. /// - Parameters: /// - input: source. - /// - queue: queue to perform parsing on. Defaults to `.global(qos: .userInitiated)` + /// - processingQueue: queue to perform parsing on. Defaults to `.global(qos: .background)` + /// - callbackQueue: queue to call callback on. Defaults to `.main` /// - completion: completion handler to call with the result. public func parse( _ input: PlaylistSource, - queue: DispatchQueue = .global(qos: .userInitiated), + processingQueue: DispatchQueue = .global(qos: .background), + callbackQueue: DispatchQueue = .main, completion: @escaping (Result) -> Void ) { - queue.async { + processingQueue.async { do { let playlist = try self.parse(input) - DispatchQueue.main.async { + callbackQueue.async { completion(.success(playlist)) } } catch { - DispatchQueue.main.async { + callbackQueue.async { completion(.failure(error)) } } @@ -148,13 +150,17 @@ public final class PlaylistParser: Parser { @available(iOS 15, tvOS 15, macOS 12, watchOS 8, *) /// Parse a playlist. /// - Parameter input: source. + /// - Parameter priority: Processing task priority. Defaults to `.background` /// - Returns: playlist. - public func parse(_ input: PlaylistSource) async throws -> Playlist { - return try await withCheckedThrowingContinuation { continuation in - self.parse(input) { result in - continuation.resume(with: result) - } + public func parse( + _ input: PlaylistSource, + priority: TaskPriority = .background + ) async throws -> Playlist { + let processingTask = Task(priority: priority) { () -> Playlist in + let playlist = try self.parse(input) + return playlist } + return try await processingTask.value } // MARK: - Helpers