What’s the best way to create a completable job as...
# coroutines
p
What’s the best way to create a completable job as a child of the current scope?
Job(parent = coroutineContext[Job])
?
g
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
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
It looks that it should work with standard structured concurrency
just lunch job in parent scope