Since the `onCompletion` argument of `produce` is ...
# coroutines
j
Since the
onCompletion
argument of
produce
is marked internal api, and it is not possible to
CoroutineStart.ATOMIC
with
produce
, how can one make sure a given resource is always released?
d
Inside the produce scope, there's
invokeOnClose()
, isn't that for cleaning up resources?
j
But the lambda of produce may not start at all...
(if is cancelled too quickly)
d
Don't you initialize the resources inside the lambda?
j
Whenever I can yes. But it is not always possible
For instance if I want to build an operator for channel. The operator has to receive an existing channel, and we have to make sure that the given channel is always consumed.
d
Isn't that why all the operators in the library are using
consume { }
?
e
But why you cannot start it
ATOMIC
j
@elizarov
produce
dooesn't have a
start
argument. Does it?
@dave08 yes, that's why all operators in kotlinx.coroutines do
onCompletion = consumes()
. But this is internal API