Skip to content

Commit

Permalink
Removed DispatchQueue Extension (to confrom to DispatchableQueue)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArielDemarco committed Dec 13, 2024
1 parent 949d7ee commit a4011e8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
30 changes: 27 additions & 3 deletions Sources/EmbraceCommonInternal/Protocols/DispatchableQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,37 @@

import Foundation

public protocol DispatchableQueue: AnyObject {
public protocol DispatchableQueue {
func async(_ block: @escaping () -> Void)
func sync(execute block: () -> Void)
}

extension DispatchQueue: DispatchableQueue {
public class DefaultDispatchableQueue: DispatchableQueue {
private let queue: DispatchQueue

init(queue: DispatchQueue) {
self.queue = queue
}

public func async(_ block: @escaping () -> Void) {
async(group: nil, execute: block)
queue.async(group: nil, execute: block)
}

public func sync(execute block: () -> Void) {
queue.sync(execute: block)
}

public static func with(label: String) -> DispatchableQueue {
DefaultDispatchableQueue(queue: .init(label: label))
}
}

public extension DispatchableQueue where Self == DefaultDispatchableQueue {
static func with(
label: String,
qos: DispatchQoS = .unspecified,
attributes: DispatchQueue.Attributes = []
) -> DispatchableQueue {
DefaultDispatchableQueue(queue: .init(label: label, qos: qos, attributes: attributes))
}
}
2 changes: 1 addition & 1 deletion Sources/EmbraceConfigInternal/EmbraceConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class EmbraceConfig {
options: Options,
notificationCenter: NotificationCenter,
logger: InternalLogger,
queue: DispatchableQueue = DispatchQueue(label: "com.embrace.config", attributes: .concurrent)
queue: DispatchableQueue = .with(label: "com.embrace.config", attributes: .concurrent)
) {
self.options = options
self.notificationCenter = notificationCenter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,6 @@ final class DefaultURLSessionTaskHandler: URLSessionTaskHandler {

private extension DefaultURLSessionTaskHandler {
static func queue() -> DispatchableQueue {
DispatchQueue(label: "com.embrace.URLSessionTaskHandler", qos: .utility)
.with(label: "com.embrace.URLSessionTaskHandler", qos: .utility)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protocol UIViewControllerHandlerDataSource: AnyObject {
class UIViewControllerHandler {

weak var dataSource: UIViewControllerHandlerDataSource?
private let queue: DispatchableQueue = DispatchQueue(label: "com.embrace.UIViewControllerHandler", qos: .utility)
private let queue: DispatchableQueue = .with(label: "com.embrace.UIViewControllerHandler", qos: .utility)

@ThreadSafe var parentSpans: [String: Span] = [:]
@ThreadSafe var viewDidLoadSpans: [String: Span] = [:]
Expand Down
2 changes: 1 addition & 1 deletion Sources/EmbraceCrash/EmbraceCrashReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final class EmbraceCrashReporter: NSObject, CrashReporter {
/// Unused in this KSCrash implementation
public var onNewReport: ((CrashReport) -> Void)?

public init(queue: DispatchableQueue = DispatchQueue(label: "com.embrace.crashreporter"),
public init(queue: DispatchableQueue = .with(label: "com.embrace.crashreporter"),
signalsBlockList: [CrashSignal] = [.SIGTERM]
) {
self.queue = queue
Expand Down

0 comments on commit a4011e8

Please sign in to comment.