https://kotlinlang.org logo
Title
j

Jonathan

10/30/2018, 4:20 PM
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

dave08

10/30/2018, 4:40 PM
Inside the produce scope, there's
invokeOnClose()
, isn't that for cleaning up resources?
j

Jonathan

10/30/2018, 4:40 PM
But the lambda of produce may not start at all...
(if is cancelled too quickly)
d

dave08

10/30/2018, 4:41 PM
Don't you initialize the resources inside the lambda?
j

Jonathan

10/30/2018, 4:42 PM
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

dave08

10/30/2018, 5:13 PM
Isn't that why all the operators in the library are using
consume { }
?
e

elizarov

10/30/2018, 6:09 PM
But why you cannot start it
ATOMIC
j

Jonathan

10/31/2018, 8:01 AM
@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