Skip to content

Commit afd0a51

Browse files
mongrisdangthaison91
authored andcommitted
Ensure running unregisterDelegate.dispose() on main thread. (#19)
* Ensure running unregisterDelegate.dispose() on main thread * Ensure dispose unregisterDelegate on main thread
1 parent a85885b commit afd0a51

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/DataSources/RxHelper/ASDelegateProxy.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ extension ObservableType {
1717
where DelegateProxy.ParentObject: ASDisplayNode {
1818

1919
let proxy = DelegateProxy.proxy(for: object)
20-
let unregisterDelegate = DelegateProxy.installForwardDelegate(dataSource, retainDelegate: retainDataSource, onProxyForObject: object)
20+
21+
// ensure dispose unregisterDelegate on main thread
22+
let unregisterDelegate = ScheduledDisposable(
23+
scheduler: MainScheduler.instance,
24+
disposable: DelegateProxy.installForwardDelegate(dataSource, retainDelegate: retainDataSource, onProxyForObject: object)
25+
)
26+
2127
// this is needed to flush any delayed old state (https://github.com/RxSwiftCommunity/RxDataSources/pull/75)
2228
object.layoutIfNeeded()
2329

@@ -49,7 +55,7 @@ extension ObservableType {
4955
default:
5056
break
5157
}
52-
}
58+
}
5359

5460
return Disposables.create { [weak object] in
5561
subscription.dispose()

0 commit comments

Comments
 (0)