Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EMBR-5972] Removed DispatchQueue Extension (to confrom to DispatchableQueue) #150

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading