Home > Net >  Difference between send and trySend
Difference between send and trySend

Time:03-31

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 send suspends 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
}
  • Related