https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

phldavies

08/20/2020, 9:02 AM
What’s the best way to create a completable job as a child of the current scope?
Job(parent = coroutineContext[Job])
?
g

gildor

08/20/2020, 9:06 AM
yes, it will work, but usually you don’t do this manually, structured concurrence does this automatically for you, just create a new scope using coroutineScope builder all start a new coroutine Do you have some particular use case?
p

phldavies

08/21/2020, 8:51 AM
I’m implementing a TCP Server, in which I want to be able to have control over cancellation to ensure disconnections can gracefully occur and buffers can be flushed. At the moment I’m using a “quit-channel” style approach, and cancelling just the socket acceptor loop, with clients being launched into a separate scope headed by a supervisor job
I’m fully aware there’s a better and more correct approach, but I can’t think of it…
g

gildor

08/21/2020, 9:04 AM
It looks that it should work with standard structured concurrency
just lunch job in parent scope
2 Views