Function mini_telegram::buffer

source ·
pub fn buffer(client: Client) -> Buffer
Expand description

Create a new client request buffer

The Client performs MTProto commands directly on the TCP connection. Only a single request may be in-flight at a given time and operations require mutable access to the Client handle. This prevents using a single MTProto connection from multiple Tokio tasks.

The strategy for dealing with this class of problem is to spawn a dedicated Tokio task to manage the MTProto connection and using “message passing” to operate on the connection. Commands are pushed into a channel. The connection task pops commands off of the channel and applies them to the MTProto connection. When the response is received, it is forwarded to the original requester.

The returned Buffer handle may be cloned before passing the new handle to separate tasks.