On channels, is there any reason you want to use t...
# coroutines
j
On channels, is there any reason you want to use tryEmit over emit, or why does it exist? Read blog post main difference emit can use buffer but not tryEmit. Got confused myself when I was trying to explain difference to a colleague. Whats the thing? 😁
o
A use case: I’m using a buffered channel to send log messages from a client to a server. Of course, such things can escalate into a DoS scenario with too many log messages being posted and the server being unable to process them at this rate. So I don’t want to suspend when the buffer is full. Rather, I’ll just drop messages and keep track of that fact, which I’ll then report later when things cool down. And tryEmit will use the buffer, but it won’t suspend when it’s full.
j
So emit in this case would get stuck because buffer full but tryEmit is not? Whats the common way of dealing with that "buffer Overflow"? I thought channel deal with it automatically.
o
There is no single common way. It always depends on context and use case.
j
In my case I have channel A using emit. In my scope I add coroutine error handler using tryEmit in channel B. Was thinking difference and if should use emit in channel B as well. But wonder if can be infinite error handler 😘