[FEATURE] - more flexible concurrency #83
Replies: 7 comments 20 replies
-
If I understand correctly, could this be solved by using only Would this approach possibly solve your issue? Its the more "pure" way of messaging between actors and can be pretty powerful. |
Beta Was this translation helpful? Give feedback.
-
Yes, that is an option. Here is my counterpoint: there is a reason kameo supports ask requests. It is common and useful to have that bidirectional request-style communication. In my mind the greatest benefit is that it makes actors kinda like async objects (in the java/oop sense), where the message passing looks like functions. I think this is an easier model to think-in than channels (and also the reason why alot of net protocols are also request response, rather than bidirectional pubsub); it's hard to think about control flow when the response is disconnected from the request ("ie. the data/event goes here, then here, then eventually works its way back around to the caller, hopefully..."). Here is my stab at a current way to do it.
In the course of writing this, this feels more solid. I'll try it out and post some code. A side note: one of the things making my head hurt here is the difference between fast and slow async. Ie. putting something in an async queue is fast, network requests are slow. When designing things, one kind has to know how long they expect any given .await to block for and when and why. |
Beta Was this translation helpful? Give feedback.
-
Kameo does let you get control of the reply oneshot channel on the Context struct using .reply_sender(). You can store this and reply at any later time which might give you some of the flexibility you're looking for |
Beta Was this translation helpful? Give feedback.
-
A random thought, but async tasks could probably be written to take a RefCell (where Self is the actor) and then as long as borrows are not held across an await point (which I believe the borrow checker would catch). It ought to be possible to write long running tasks as regular async functions, without having to spawn tasks, or deal with the shared state spawning creates. (ie. no members of the Actor struct need Arc/Mutex) ( Then the question is what polls the tasks, and how would tasks be defined and queued ) |
Beta Was this translation helpful? Give feedback.
-
Another sticking point I bumped into is that it would be nice if there was a way to spawn an Actor defered, where the Actor is returned by a future, but you get the ActorRef right away. This would help to avoid having to Option wrap Actor fields which are initialized in on_startup. |
Beta Was this translation helpful? Give feedback.
-
Thoughts on latching messages for state machine.
EDIT: |
Beta Was this translation helpful? Give feedback.
-
Do you have any thoughts on making a PubSub type which works for all message types which implement a trait (probably should be called Topic). I am trying to make something now which lazily spins up a global PubSub when something tries to publish or subscribe to M. I think this makes ergonomic sense for UseCases where things are very decoupled. Ex) I want to put publish hooks into my discord client for when messages are received, but only in some configurations will anyone be listening. I think there is an argument that the pubsub broker should be explicitly instantiated, and passed to the actor, but I definitely think ad-hoc muxing over the Type of message is a good idea (similar to how we mux over actor messages). |
Beta Was this translation helpful? Give feedback.
-
Motivation
Lets say my actor represents a client to an API. Among the things this actor does is request data on Items. The requests are batched using an internal queue and a separate task, but we want the actor to be able for the individual items. The initial handling of the request does need &mut, (to add items to the queue), but waiting on the result does not need (and cannot hold up) the &mut Self.
ie. it is a class of problem which has a sequential mutable part, and a concurrent part
(and really it might need the &mut after the current part as well.)
Proposed Solution
None. Want to open this discussion.
Alternatives Considered
Returning a one-shot channel.
Beta Was this translation helpful? Give feedback.
All reactions