Skip to content
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
29 changes: 15 additions & 14 deletions Dependencies.xcworkspace/xcshareddata/swiftpm/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 20 additions & 21 deletions Sources/Dependencies/WithDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ public func withDependencies<R>(
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void,
operation: () async throws -> R
) async rethrows -> R {
try await isSetting(true) {
#if DEBUG
try await DependencyValues.$isSetting.withValue(true) {
var dependencies = DependencyValues._current
try await updateValuesForOperation(&dependencies)
return try await DependencyValues.$_current.withValue(dependencies) {
try await isSetting(false) {
try await DependencyValues.$isSetting.withValue(false) {
let result = try await operation()
if R.self is AnyClass {
dependencyObjects.store(result as AnyObject)
Expand All @@ -78,6 +79,17 @@ public func withDependencies<R>(
}
}
}
#else
var dependencies = DependencyValues._current
try await updateValuesForOperation(&dependencies)
return try await DependencyValues.$_current.withValue(dependencies) {
let result = try await operation()
if R.self is AnyClass {
dependencyObjects.store(result as AnyObject)
}
return result
}
#endif
}
#else
@_unsafeInheritExecutor
Expand Down Expand Up @@ -471,27 +483,14 @@ private func isSetting<R>(
_ value: Bool,
operation: () throws -> R
) rethrows -> R {
#if DEBUG
try DependencyValues.$isSetting.withValue(value, operation: operation)
#else
try operation()
#endif
#if DEBUG
try DependencyValues.$isSetting.withValue(value, operation: operation)
#else
try operation()
#endif
}

#if swift(>=6)
@_transparent
private func isSetting<R>(
_ value: Bool,
isolation: isolated (any Actor)? = #isolation,
operation: () async throws -> R
) async rethrows -> R {
#if DEBUG
try await DependencyValues.$isSetting.withValue(value, operation: operation)
#else
try await operation()
#endif
}
#else
#if swift(<6)
@_transparent
private func isSetting<R>(
_ value: Bool,
Expand Down