@@ -65,11 +65,12 @@ public func withDependencies<R>(
65
65
_ updateValuesForOperation: ( inout DependencyValues ) async throws -> Void ,
66
66
operation: ( ) async throws -> R
67
67
) async rethrows -> R {
68
- try await isSetting ( true ) {
68
+ #if DEBUG
69
+ try await DependencyValues . $isSetting. withValue ( true ) {
69
70
var dependencies = DependencyValues . _current
70
71
try await updateValuesForOperation ( & dependencies)
71
72
return try await DependencyValues . $_current. withValue ( dependencies) {
72
- try await isSetting ( false ) {
73
+ try await DependencyValues . $ isSetting. withValue ( false ) {
73
74
let result = try await operation ( )
74
75
if R . self is AnyClass {
75
76
dependencyObjects. store ( result as AnyObject )
@@ -78,6 +79,17 @@ public func withDependencies<R>(
78
79
}
79
80
}
80
81
}
82
+ #else
83
+ var dependencies = DependencyValues . _current
84
+ try await updateValuesForOperation ( & dependencies)
85
+ return try await DependencyValues . $_current. withValue ( dependencies) {
86
+ let result = try await operation ( )
87
+ if R . self is AnyClass {
88
+ dependencyObjects. store ( result as AnyObject )
89
+ }
90
+ return result
91
+ }
92
+ #endif
81
93
}
82
94
#else
83
95
@_unsafeInheritExecutor
@@ -471,27 +483,14 @@ private func isSetting<R>(
471
483
_ value: Bool ,
472
484
operation: ( ) throws -> R
473
485
) rethrows -> R {
474
- #if DEBUG
475
- try DependencyValues . $isSetting. withValue ( value, operation: operation)
476
- #else
477
- try operation ( )
478
- #endif
486
+ #if DEBUG
487
+ try DependencyValues . $isSetting. withValue ( value, operation: operation)
488
+ #else
489
+ try operation ( )
490
+ #endif
479
491
}
480
492
481
- #if swift(>=6)
482
- @_transparent
483
- private func isSetting< R> (
484
- _ value: Bool ,
485
- isolation: isolated ( any Actor ) ? = #isolation,
486
- operation: ( ) async throws -> R
487
- ) async rethrows -> R {
488
- #if DEBUG
489
- try await DependencyValues . $isSetting. withValue ( value, operation: operation)
490
- #else
491
- try await operation ( )
492
- #endif
493
- }
494
- #else
493
+ #if swift(<6)
495
494
@_transparent
496
495
private func isSetting< R> (
497
496
_ value: Bool ,
0 commit comments