Sasha Arutyunyan
Sasha Arutyunyan

Reputation: 105

Difference between send and trySend

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.

Upvotes: 2

Views: 1705

Answers (1)

guipivoto
guipivoto

Reputation: 18687

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
}

Upvotes: 4

Related Questions