Merge pull request #391 from mpretty-cyro/fix/dependency-access-crash

Dependency access crash fix
pull/1061/head
Morgan Pretty 2 months ago committed by GitHub
commit 231a3f882a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -386,7 +386,10 @@ private extension Dependencies {
/// Convenience method to retrieve the existing dependency instance from memory in a thread-safe way /// Convenience method to retrieve the existing dependency instance from memory in a thread-safe way
private func getValue<T>(_ key: String, of variant: DependencyStorage.Key.Variant) -> T? { private func getValue<T>(_ key: String, of variant: DependencyStorage.Key.Variant) -> T? {
guard let typedValue: DependencyStorage.Value = storage.instances[variant.key(key)] else { return nil } return _storage.performMap { storage in
guard let typedValue: DependencyStorage.Value = storage.instances[variant.key(key)] else {
return nil
}
guard let result: T = typedValue.value(as: T.self) else { guard let result: T = typedValue.value(as: T.self) else {
/// If there is a value stored for the key, but it's not the right type then something has gone wrong, and we should log /// If there is a value stored for the key, but it's not the right type then something has gone wrong, and we should log
Log.critical("Failed to convert stored dependency '\(variant.key(key))' to expected type: \(T.self)") Log.critical("Failed to convert stored dependency '\(variant.key(key))' to expected type: \(T.self)")
@ -395,6 +398,7 @@ private extension Dependencies {
return result return result
} }
}
/// Convenience method to store a dependency instance in memory in a thread-safe way /// Convenience method to store a dependency instance in memory in a thread-safe way
@discardableResult private func setValue<T>(_ value: T, typedStorage: DependencyStorage.Value, key: String) -> T { @discardableResult private func setValue<T>(_ value: T, typedStorage: DependencyStorage.Value, key: String) -> T {

Loading…
Cancel
Save