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 {
110110 }
111111 }
112112
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( ) {
131114 observations. removeAll ( )
132115 lookups. removeAll ( )
133- return tracker
134116 }
135117
136118 internal mutating func willSet( keyPath: AnyKeyPath ) -> [ @Sendable ( AnyKeyPath ) -> Void ] {
@@ -175,8 +157,8 @@ public struct ObservationRegistrar: Sendable {
175157 state. withCriticalRegion { $0. cancel ( id) }
176158 }
177159
178- internal func deinitialize ( ) {
179- state. withCriticalRegion { $0. deinitialize ( ) } ? ( )
160+ internal func cancelAll ( ) {
161+ state. withCriticalRegion { $0. cancelAll ( ) }
180162 }
181163
182164 internal func willSet< Subject: Observable , Member> (
@@ -207,7 +189,7 @@ public struct ObservationRegistrar: Sendable {
207189 }
208190
209191 deinit {
210- context. deinitialize ( )
192+ context. cancelAll ( )
211193 }
212194 }
213195
Original file line number Diff line number Diff line change @@ -287,22 +287,6 @@ final class CowTest {
287287 var container = CowContainer ( )
288288}
289289
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-
306290@main
307291struct Validator {
308292 @MainActor
@@ -527,23 +511,6 @@ struct Validator {
527511 expectEqual ( subject. container. id, startId)
528512 }
529513
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-
547514 runAllTests ( )
548515 }
549516}
You can’t perform that action at this time.
0 commit comments