File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,8 +75,8 @@ class HybridRiveView: HybridRiveViewSpec {
7575 }
7676
7777 func playIfNeeded( ) {
78- onMainSync {
79- try ? self . getRiveView ( ) . playIfNeeded ( )
78+ try ? onMainSync {
79+ try self . getRiveView ( ) . playIfNeeded ( )
8080 }
8181 }
8282
@@ -263,14 +263,19 @@ class HybridRiveView: HybridRiveViewSpec {
263263}
264264
265265extension HybridRiveView {
266- /// Runs a closure on the main thread. If already on main, executes directly
267- /// to avoid deadlocking with DispatchQueue.main.sync.
268- func onMainSync< T> ( _ work: ( ) throws -> T ) rethrows -> T {
266+ /// Runs a @MainActor-isolated closure on the main thread.
267+ /// If already on main, uses assumeIsolated directly.
268+ /// If on another thread, dispatches synchronously to main first.
269+ func onMainSync< T> ( _ work: @MainActor ( ) throws -> T ) throws -> T {
269270 if Thread . isMainThread {
270- return try work ( )
271+ return try MainActor . assumeIsolated {
272+ try work ( )
273+ }
271274 }
272- return try onMainSync {
273- try work ( )
275+ return try DispatchQueue . main. sync {
276+ MainActor . assumeIsolated {
277+ try work ( )
278+ }
274279 }
275280 }
276281
You can’t perform that action at this time.
0 commit comments