Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ded1b7fb authored by moezbhatti's avatar moezbhatti
Browse files

Check if emitter is already disposed

parent cb169217
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -52,13 +52,22 @@ class ChangelogManagerImpl @Inject constructor(

        return Single
                .create<Response> { emitter ->
                    call?.enqueue(object : Callback {
                        override fun onResponse(call: Call, response: Response) {
                            if (!emitter.isDisposed) {
                                emitter.onSuccess(response)
                            }
                        }

                        override fun onFailure(call: Call, e: IOException) {
                            if (!emitter.isDisposed) {
                                emitter.onError(e)
                            }
                        }
                    })
                    emitter.setCancellable {
                        call?.cancel()
                    }
                    call?.enqueue(object : Callback {
                        override fun onResponse(call: Call, response: Response) = emitter.onSuccess(response)
                        override fun onFailure(call: Call, e: IOException) = emitter.onError(e)
                    })
                }
                .map { response -> response.body?.string()?.let(adapter::fromJson) }
                .map { response ->
+1 −2
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.withLatestFrom
import io.reactivex.schedulers.Schedulers
import io.realm.Realm
import timber.log.Timber
import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@@ -160,7 +159,7 @@ class MainViewModel @Inject constructor(
                        .subscribe({ changelog ->
                            changelogManager.markChangelogSeen()
                            view.showChangelog(changelog)
                        }, Timber::w)
                        }, {}) // Ignore error
            } else {
                changelogManager.markChangelogSeen()
            }