Skip to content

Commit

Permalink
Check if emitter is already disposed
Browse files Browse the repository at this point in the history
  • Loading branch information
moezbhatti committed Sep 11, 2019
1 parent cb16921 commit ded1b7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 13 additions & 4 deletions data/src/main/java/com/moez/QKSMS/manager/ChangelogManagerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -160,7 +159,7 @@ class MainViewModel @Inject constructor(
.subscribe({ changelog ->
changelogManager.markChangelogSeen()
view.showChangelog(changelog)
}, Timber::w)
}, {}) // Ignore error
} else {
changelogManager.markChangelogSeen()
}
Expand Down

0 comments on commit ded1b7f

Please sign in to comment.