-
-
Notifications
You must be signed in to change notification settings - Fork 572
Actor model on top of cats? #2627
-
|
Hi there - I might be missing something (seriously - I am frantically catching up), but an Actor model on top of Cats Effects seems like a no-brainer to me, but there doesn't seem to be one. How do you manage long running, independant, but identifiable processes? A process per session on a web server for example, or a process per long running async something or other. I'd assume Fiber, but:
As I say, this Q is firstly "why is an actor model on top of cats a bad idea" and maybe secondly "what do people do instead" :-) |
Beta Was this translation helpful? Give feedback.
All reactions
I arrived to CE3 from Akka world, so I also had a hard time wrapping my head around this one at first :) still do sometimes!
How do you manage long running, independant, but identifiable processes? A process per session on a web server for example, or a process per long running async something or other.
Yes, fibers are indeed the answer. They are lightweight and generally awesome!
why doesn't this already exist - I must be missing something
It is fairly straightforward to make an "actor" using fs2's Channel API.
def send(a: A): F[Either[Channel.Closed, Unit]]
def stream: Stream[F, A]
}
https://github.com/typelevel/fs2/blob/main/core/shared/src/main/scala/f...
Replies: 6 comments 10 replies
-
|
I arrived to CE3 from Akka world, so I also had a hard time wrapping my head around this one at first :) still do sometimes!
Yes, fibers are indeed the answer. They are lightweight and generally awesome!
It is fairly straightforward to make an "actor" using fs2's trait Channel[F[_], A] {
def send(a: A): F[Either[Channel.Closed, Unit]] def stream: Stream[F, A] } https://github.com/typelevel/fs2/blob/main/core/shared/src/main/scala/fs2/concurrent/Channel.scala The
As for why this pattern is not so popular, I think it just doesn't lend itself well to the FP paradigm :) consider the example of web server, for example. http4s models this concept as a function Anyway just my 2 cents, maybe someone smarter can give us both some real insight on the matter |
Beta Was this translation helpful? Give feedback.
All reactions
-
1
-
|
Thanks! That was really helpful. Unfortunately I do want exactly the actor model. Essentially I want a "persistent object" that represents each user so it can progress a user's long running status. I could of course turn it into a messages/event paradigm, or have a single state/map which represents all user's state. I'm read this as "the actor paradigm is about maintaining state and being side effectful, both of which have different solutions in a strict FP environment" :-) |
Beta Was this translation helpful? Give feedback.
All reactions
-
this is a fantastic summary.
Following from the above, FWIW I'm sure there is some pattern that can get you where you need. E.g. the |
Beta Was this translation helpful? Give feedback.
All reactions
-
1 -
1
-
You can have an abstraction over this with This talk should be a good starting point: https://systemfw.org/talks.html#scala-italy-2019 |
Beta Was this translation helpful? Give feedback.
All reactions
-
1
-
|
Especially with the help of @ChristopherDavenport https://github.com/davenverse/mapref , which is soon coming to cats-effect but you can use as a library now |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Thanks! |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
this was too on-point :-) https://twitter.com/buitengebieden_/status/1467439671865229314 |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Sadly that Tweet has gone. |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Perhaps you should talk to @alcestes on the topic of Actors and cats effects. I put together a Twitter thread earlier this year on some of his talks and pointers to his work https://twitter.com/bblfish/status/1358392715118010369 |
Beta Was this translation helpful? Give feedback.
All reactions
-
1
-
|
Thanks! |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
It would be useful to put together a list of use cases where actors are very useful and cannot be so easily done without.
|
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Thing is, all those things are easily done with cats-effect without actors, and in fact arguably more easily than with actors |
Beta Was this translation helpful? Give feedback.
All reactions
-
1
-
|
Do you have some reading on how one would do that? I would like to understand at what point the Actor concepts start becoming important. |
Beta Was this translation helpful? Give feedback.
All reactions
This comment was marked as spam.
This comment was marked as spam.
-
|
If you are still looking for actors, I put together a small gists using CE3, Ref, Deferred, magic. https://gist.github.com/Swoorup/1ac9b69e0c0f1c0925d1397a94b0a762 |
Beta Was this translation helpful? Give feedback.
All reactions
-
2
-
|
thanks! |
Beta Was this translation helpful? Give feedback.