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

vaskir

06/11/2020, 1:38 PM
there is
actor { }
c

Casey Brooks

06/11/2020, 1:40 PM
that’s only available on JVM. I’m needing some way to have similar functionality in an MPP app. Besides,
actor { }
is deprecated, so I don’t really want to get bought into an API that is not being supported and may be removed
z

Zach Klippenstein (he/him) [MOD]

06/11/2020, 1:55 PM
Flow and actors are completely unrelated. If you need a full-fledged actor library, even
actor
would be insufficient, but if you just want to serialized concurrent access to mutable state it's really easy to just make an inbox channel and launch a coroutine to read from it and process messages (basically all
actor
does anyway). All the pieces for that should be available for multiplatform, I'm surprised
actor
isn't.
👍 1
c

Casey Brooks

06/11/2020, 2:19 PM
Yeah, I’m not needing anything too crazy. Basically just need to process a stream of events that do some computation and then update/replace an immutable state object. I was hoping for a higher-level API that using channels directly, but I will give that a shot
z

Zach Klippenstein (he/him) [MOD]

06/11/2020, 2:29 PM
Sounds like you could also just implement that as a stream transformer with Flow. The flow approach is more push-based, the actor one is more pull-based. Maybe one advantage of the actor approach is that it focuses on ownership of the processor – you explicitly launch a single coroutine to do the processing from a single channel, it’s clear there’s only one of each and what their lifetime is. With a flow approach, something like
events.transform { … }.stateIn(scope)
, fact that there’s a single transformer and inbox is implied by the
stateIn
, but it’s less obvious. Also,
stateIn
doesn’t exist yet 😅
h

henrikhorbovyi

06/11/2020, 3:54 PM
actor
will be deprecated in the future yeah? 🤔
b

bdawg.io

06/11/2020, 4:38 PM
The current form of actors are not so much deprecated as obsolete, in they are working on a new design for them to support more complex use cases. I would be quite surprised if they break binary compatibility even once the new design is finished and released
h

henrikhorbovyi

06/11/2020, 5:05 PM
Got it... I just don't use it because the docs say to do so 😄
4 Views