@@ -56,10 +56,9 @@ import ConcurrencyExtras
5656 /// - Returns: A token that keeps the subscription alive. Observation is cancelled when the token
5757 /// is deallocated.
5858 public func observe(
59- isolation: ( any Actor ) ? = #isolation,
60- @_inheritActorContext _ apply: @escaping @Sendable ( ) -> Void
59+ @_inheritActorContext _ apply: @escaping @isolated ( any) @Sendable ( ) -> Void
6160 ) -> ObserveToken {
62- observe ( isolation : isolation ) { _ in apply ( ) }
61+ observe { _ in Result ( catching : apply) . get ( ) }
6362 }
6463
6564 /// Tracks access to properties of an observable model.
@@ -72,37 +71,21 @@ import ConcurrencyExtras
7271 /// - Returns: A token that keeps the subscription alive. Observation is cancelled when the token
7372 /// is deallocated.
7473 public func observe(
75- isolation : ( any Actor ) ? = #isolation ,
76- @ _inheritActorContext _ apply: @escaping @Sendable ( _ transaction: UITransaction ) -> Void
74+ @ _inheritActorContext
75+ _ apply: @escaping @ isolated ( any ) @Sendable ( _ transaction: UITransaction ) -> Void
7776 ) -> ObserveToken {
78- let actor = ActorProxy ( base: isolation)
79- return observe (
77+ _observe (
8078 apply,
8179 task: { transaction, operation in
8280 Task {
83- await actor . perform {
84- operation ( )
85- }
81+ await operation ( )
8682 }
8783 }
8884 )
8985 }
9086#endif
9187
92- private actor ActorProxy {
93- let base : ( any Actor ) ?
94- init ( base: ( any Actor ) ? ) {
95- self . base = base
96- }
97- nonisolated var unownedExecutor : UnownedSerialExecutor {
98- ( base ?? MainActor . shared) . unownedExecutor
99- }
100- func perform( _ operation: @Sendable ( ) -> Void ) {
101- operation ( )
102- }
103- }
104-
105- func observe(
88+ func _observe(
10689 _ apply: @escaping @Sendable ( _ transaction: UITransaction ) -> Void ,
10790 task: @escaping @Sendable (
10891 _ transaction: UITransaction , _ operation: @escaping @Sendable ( ) -> Void
@@ -141,7 +124,7 @@ func observe(
141124private func onChange(
142125 _ apply: @escaping @Sendable ( _ transaction: UITransaction ) -> Void ,
143126 task: @escaping @Sendable (
144- _ transaction: UITransaction , _ operation: @escaping @Sendable ( ) -> Void
127+ _ transaction: UITransaction , _ operation: @escaping @isolated ( any ) @ Sendable ( ) -> Void
145128 ) -> Void
146129) {
147130 withPerceptionTracking {
0 commit comments