We're trying to perform some tasks sequentially an...
# coroutines
l
We're trying to perform some tasks sequentially and i was wondering if an actor or a Mutex is better suited for this case. There'd be many queues and each of them will be processing few tasks.
z
a mutex is the coroutines version of a lock that is non-re-entrant
I find code that uses locks difficult to work with, and the fact that a mutex is non-re-entrant makes it even more difficult
that said, you can make a mutex re-entrant with the code shown here https://elizarov.medium.com/phantom-of-the-coroutine-afc63b03a131
however I love actors and find them delightful to use, but there’s some boilerplate around setting them up
l
I know the difference between them but I'm not sure which one is better for this specific case. I'm not very enthusiastic about having hundreds of channels.
z
do you need multiple queues? or a single queue that distributes work to multiple “workers”
l
Multiple queues
z
okay yeah then an actor seems appropriate
does your actor need to shut down after completing its work?
l
Possibly, to save memory
z
(an actor would just be a coroutine that maintains a queue of work to be done in the form of a channel)
would each actor have its own on-going state?
l
Yes
z
yeah, an actor definitely seems appropriate then
allows you to define state unique to that actor, separate from other actors
l
I see, "the state" is a good point. Thanks for the input