What is the difference between send and trySend in callbaFlow?
I know that trySend returtn ChannelResult but I don't understand the next statement.
This is synchronous variant of [send], which backs off in situations when
sendsuspends or throws.
CodePudding user response:
send is a suspend function. So, it can only be invoked from a suspend function.
trySend is a regular function and it is synchronous. In other words, when you invoke trySend, you immediately get the result.
So, for example, with trySend you can do as follows:
if(trySend(element) == /*expected result*/) {
//doSomething
}
