Add @unchecked Sendable conformance and @Sendable handler to DIContainer
This commit is contained in:
parent
2280142fe1
commit
c3a971b49e
1 changed files with 4 additions and 4 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import Foundation
|
||||
|
||||
public final class DIContainer {
|
||||
public final class DIContainer: @unchecked Sendable {
|
||||
|
||||
public static let shared = DIContainer()
|
||||
public private(set) var values = InjectionValues()
|
||||
private var observers: [AnyKeyPath: [UUID: () -> Void]] = [:]
|
||||
private var observers: [AnyKeyPath: [UUID: @Sendable () -> Void]] = [:]
|
||||
private let lock = NSLock()
|
||||
|
||||
private init() {}
|
||||
|
|
@ -36,7 +36,7 @@ public final class DIContainer {
|
|||
@discardableResult
|
||||
func addObserver<T>(
|
||||
for keyPath: KeyPath<InjectionValues, T?>,
|
||||
handler: @escaping () -> Void
|
||||
handler: @escaping @Sendable () -> Void
|
||||
) -> UUID {
|
||||
let id = UUID()
|
||||
lock.withLock {
|
||||
|
|
@ -54,7 +54,7 @@ public final class DIContainer {
|
|||
}
|
||||
|
||||
private func notifyObservers(for keyPath: AnyKeyPath) {
|
||||
let handlers: [() -> Void] = lock.withLock {
|
||||
let handlers: [@Sendable () -> Void] = lock.withLock {
|
||||
Array(observers[keyPath]?.values ?? [])
|
||||
}
|
||||
handlers.forEach { $0() }
|
||||
|
|
|
|||
Loading…
Reference in a new issue