@@ -189,7 +189,8 @@ public struct AtomRelationContext: AtomWatchableContext {
189189 /// - Parameter object: An object that to be retained.
190190 @inlinable
191191 public func keepUntilTermination< Object: AnyObject > ( _ object: Object ) {
192- _box. keepUntilTermination ( object)
192+ let retainer = ObjectRetainer ( object)
193+ addTermination ( retainer. release)
193194 }
194195}
195196
@@ -200,23 +201,10 @@ internal protocol _AnyAtomRelationContextBox {
200201
201202 func watch< Node: Atom > ( _ atom: Node , shouldNotifyAfterUpdates: Bool ) -> Node . State . Value
202203 func addTermination( _ termination: @MainActor @escaping ( ) -> Void )
203- func keepUntilTermination< Object: AnyObject > ( _ object: Object )
204204}
205205
206206@usableFromInline
207207internal struct _AtomRelationContextBox < Caller: Atom > : _AnyAtomRelationContextBox {
208- final class Retainer < Object: AnyObject > {
209- private var object : Object ?
210-
211- init ( _ object: Object ) {
212- self . object = object
213- }
214-
215- func release( ) {
216- object = nil
217- }
218- }
219-
220208 let caller : Caller
221209
222210 @usableFromInline
@@ -235,10 +223,19 @@ internal struct _AtomRelationContextBox<Caller: Atom>: _AnyAtomRelationContextBo
235223 func addTermination( _ termination: @MainActor @escaping ( ) -> Void ) {
236224 store. addTermination ( caller, termination: termination)
237225 }
226+ }
227+
228+ @usableFromInline
229+ internal final class ObjectRetainer < Object: AnyObject > {
230+ private var object : Object ?
231+
232+ @usableFromInline
233+ init ( _ object: Object ) {
234+ self . object = object
235+ }
238236
239237 @usableFromInline
240- func keepUntilTermination< Object: AnyObject > ( _ object: Object ) {
241- let retainer = Retainer ( object)
242- store. addTermination ( caller, termination: retainer. release)
238+ func release( ) {
239+ object = nil
243240 }
244241}
0 commit comments