Skip to content

Commit

Permalink
catch offer exceptions. See Kotlin/kotlinx.coroutines#974 (#2007)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9e2a24f)
  • Loading branch information
martinbonnin authored and tasomaniac committed Mar 23, 2020
1 parent 38b1186 commit bbf47ed
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import kotlinx.coroutines.flow.*

private class ChannelCallback<T>(val channel: Channel<Response<T>>) : ApolloCall.Callback<T>() {

@ExperimentalCoroutinesApi
override fun onResponse(response: Response<T>) {
if (!channel.isClosedForSend) {
runCatching {
channel.offer(response)
}
}
Expand Down Expand Up @@ -196,7 +195,9 @@ fun <T> ApolloSubscriptionCall<T>.toChannel(capacity: Int = Channel.UNLIMITED):
}

override fun onResponse(response: Response<T>) {
channel.offer(response)
runCatching {
channel.offer(response)
}
}

override fun onFailure(e: ApolloException) {
Expand Down

0 comments on commit bbf47ed

Please sign in to comment.