yielding

Express the lambda toReturn when the sharing computation is done. Usually the toReturn value is different from the toSend, otherwise use share without calling this function to return the value toSend. It can be used with checks after the invocation.

Example

val result = sharing(0) {
val maxValue = it.maxBy { v -> v.value }.value
maxValue.yielding { "A string" }
}
result // result: Kotlin.String
val result = sharing(0) {
val max = it.maxBy { v -> v.value }.value
max.yielding { "Hello".takeIf { min 1 } }
}
result // result: Kotlin.String?

The invoke of yielding as the last statement of the body of the share, sent to the neighbours the toSend value, but returns from the share the toReturn value.