File tree Expand file tree Collapse file tree 2 files changed +4
-55
lines changed
stdlib/public/Observation/Sources/Observation Expand file tree Collapse file tree 2 files changed +4
-55
lines changed Original file line number Diff line number Diff line change @@ -110,27 +110,9 @@ public struct ObservationRegistrar: Sendable {
110
110
}
111
111
}
112
112
113
- internal mutating func deinitialize( ) -> ( @Sendable ( ) -> Void ) ? {
114
- func extractSelf< T> ( _ ty: T . Type ) -> AnyKeyPath {
115
- return \T . self
116
- }
117
-
118
- var tracker : ( @Sendable ( ) -> Void ) ?
119
- lookupIteration: for (keyPath, ids) in lookups {
120
- for id in ids {
121
- if let found = observations [ id] ? . willSetTracker {
122
- // convert the keyPath into its \Self.self version
123
- let selfKp = _openExistential ( type ( of: keyPath) . rootType, do: extractSelf)
124
- tracker = {
125
- found ( selfKp)
126
- }
127
- break lookupIteration
128
- }
129
- }
130
- }
113
+ internal mutating func cancelAll( ) {
131
114
observations. removeAll ( )
132
115
lookups. removeAll ( )
133
- return tracker
134
116
}
135
117
136
118
internal mutating func willSet( keyPath: AnyKeyPath ) -> [ @Sendable ( AnyKeyPath ) -> Void ] {
@@ -175,8 +157,8 @@ public struct ObservationRegistrar: Sendable {
175
157
state. withCriticalRegion { $0. cancel ( id) }
176
158
}
177
159
178
- internal func deinitialize ( ) {
179
- state. withCriticalRegion { $0. deinitialize ( ) } ? ( )
160
+ internal func cancelAll ( ) {
161
+ state. withCriticalRegion { $0. cancelAll ( ) }
180
162
}
181
163
182
164
internal func willSet< Subject: Observable , Member> (
@@ -207,7 +189,7 @@ public struct ObservationRegistrar: Sendable {
207
189
}
208
190
209
191
deinit {
210
- context. deinitialize ( )
192
+ context. cancelAll ( )
211
193
}
212
194
}
213
195
Original file line number Diff line number Diff line change @@ -287,22 +287,6 @@ final class CowTest {
287
287
var container = CowContainer ( )
288
288
}
289
289
290
- @Observable
291
- final class DeinitTriggeredObserver {
292
- var property : Int = 3
293
- var property2 : Int = 4
294
- let deinitTrigger : ( ) -> Void
295
-
296
- init ( _ deinitTrigger: @escaping ( ) -> Void ) {
297
- self . deinitTrigger = deinitTrigger
298
- }
299
-
300
- deinit {
301
- deinitTrigger ( )
302
- }
303
- }
304
-
305
-
306
290
@main
307
291
struct Validator {
308
292
@MainActor
@@ -527,23 +511,6 @@ struct Validator {
527
511
expectEqual ( subject. container. id, startId)
528
512
}
529
513
530
- suite. test ( " weak container observation " ) {
531
- let changed = CapturedState ( state: false )
532
- let deinitialized = CapturedState ( state: 0 )
533
- var test = DeinitTriggeredObserver {
534
- deinitialized. state += 1
535
- }
536
- withObservationTracking { [ weak test] in
537
- _blackHole ( test? . property)
538
- _blackHole ( test? . property2)
539
- } onChange: {
540
- changed. state = true
541
- }
542
- test = DeinitTriggeredObserver { }
543
- expectEqual ( deinitialized. state, 1 ) // ensure only one invocation is done per deinitialization
544
- expectEqual ( changed. state, true )
545
- }
546
-
547
514
runAllTests ( )
548
515
}
549
516
}
You can’t perform that action at this time.
0 commit comments