diff --git a/Sources/DataSources/RxHelper/ASDelegateProxy.swift b/Sources/DataSources/RxHelper/ASDelegateProxy.swift index a9ad933..f87bae6 100644 --- a/Sources/DataSources/RxHelper/ASDelegateProxy.swift +++ b/Sources/DataSources/RxHelper/ASDelegateProxy.swift @@ -17,7 +17,13 @@ extension ObservableType { where DelegateProxy.ParentObject: ASDisplayNode { let proxy = DelegateProxy.proxy(for: object) - let unregisterDelegate = DelegateProxy.installForwardDelegate(dataSource, retainDelegate: retainDataSource, onProxyForObject: object) + + // ensure dispose unregisterDelegate on main thread + let unregisterDelegate = ScheduledDisposable( + scheduler: MainScheduler.instance, + disposable: DelegateProxy.installForwardDelegate(dataSource, retainDelegate: retainDataSource, onProxyForObject: object) + ) + // this is needed to flush any delayed old state (https://github.com/RxSwiftCommunity/RxDataSources/pull/75) object.layoutIfNeeded() @@ -49,7 +55,7 @@ extension ObservableType { default: break } - } + } return Disposables.create { [weak object] in subscription.dispose()