Warning
This post was published 37 days ago. The information described in this article may have changed.
I'm trying to write a client/connector for some websocket based api. And I decide to implement it by build actors with tokio directly as decribed in this article: Actors with Tokio – Alice Ryhl.
The article specially mentioned how to handle a connection:
Multiple actors sharing a handle
Just like you can have multiple handles per actor, you can also have multiple actors per handle. The most common example of this is when handling a connection such as aTcpStream
, where you commonly spawn two tasks: one for reading and one for writing. When using this pattern, you make the reading and writing tasks as simple as you can — their only job is to do IO. The reader task will just send any messages it receives to some other task, typically another actor, and the writer task will just forward any messages it receives to the connection.
I have several questions about it:
ConnHandle
?send(message)
to send message to it via internal channel. But the reading actor is a bit different - unlike typical actors that you send message to, it send messages to you, or you receive messages from it instead. So the question is how to design the api for it?1 post - 1 participant
🏷️ rust_feed