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

xenomachina

03/10/2021, 6:22 PM
I find that I frequently need a Job+SendChannel that sends to that job, where the Job acts as a consumer on the channel (internally it has the corresponding ReceiveChannel) and the job exits once the channel is closed for receive. I've built some small helper classes&functions to help with this, but I'm wondering if there's something already in kotlinx.coroutines I missed, or if there's some reason I shouldn't be doing things this way.
a

Adam Powell

03/10/2021, 6:39 PM
CoroutineScope.actor
?
x

xenomachina

03/10/2021, 7:04 PM
Thanks @Adam Powell! Yeah, that sounds like what I'm looking for. I see it's annotated
@ObsoleteCoroutinesApi
, though. What is the non-obsolete alternative? The docs link to an issue with a 3.5 year long discussion, but no clear answer.
a

Adam Powell

03/10/2021, 7:08 PM
probably exactly what you're already doing 🙂
but the pattern does have a long precedent, as you can see
x

xenomachina

03/10/2021, 7:18 PM
Yeah, I'd expect it to be a very common thing to want to do. Very unfortunate that the existing API is marked obsolete before a replacement has been released. 😕
a

Adam Powell

03/10/2021, 7:27 PM
a bit awkward, but it's still usable as-is, and replacing it should it be removed is a rather quick matter given the simplicity of the pattern.
3 Views