Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse RxJava built-in disposed Disposable #1841

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions reactive/kotlinx-coroutines-rx2/src/RxConvert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ public fun <T: Any> ObservableSource<T>.asFlow(): Flow<T> = callbackFlow {
}

subscribe(observer)
awaitClose { disposableRef.getAndSet(Disposed)?.dispose() }
}

private object Disposed : Disposable {
override fun isDisposed() = true
override fun dispose() = Unit
awaitClose { disposableRef.getAndSet(Disposables.disposed())?.dispose() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I treated this private object Disposed as a private "token" similarly to DisposableHelper.DISPOSED in Rx itself (they have the warning there "don't leak it"), but here I didn't do compareAndSet(Disposed, ...) because comparing to initial null was enough, so I think your change is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Just trying to save APK size anywhere I can by reusing existing stuff.

}

/**
Expand Down