#agent #tokio #tokio-agent

tokio-agent

Agents are a simple abstraction around state, inspired by Elixir's Agent

2 releases

0.1.1 Mar 18, 2025
0.1.0 May 19, 2022

#425 in Concurrency

Download history 1/week @ 2024-12-11 2/week @ 2025-02-26 64/week @ 2025-03-12 117/week @ 2025-03-19

183 downloads per month

MIT license

26KB
287 lines

"Agents are a simple abstraction around state."

This crate is inspired by Elixir's Agent.

In Rust however, an Agent holds your State in either a tokio task, or a thread, and allows you to interact with that state, while having the state remain within the task or thread.

An agent managing state in a thread for examplue could be used to manage and interact with a resource which would cause blocking on the tokio runtime (for example, sqlite database).

An agent managing state in a task could be used to manage and interact with a resource in a lock-free way.


lib.rs:

"Agents are a simple abstraction around state."

This crate is inspired by Elixir's Agent.

In Rust however, an Agent holds your State in either a tokio task, or a thread, and allows you to interact with that state, while having the state remain within the task or thread.

An agent managing state in a thread for examplue could be used to manage and interact with a resource which would cause blocking on the tokio runtime (for example, sqlite database).

An agent managing state in a task could be used to manage and interact with a resource in a lock-free way.

Dependencies

~2–7.5MB
~47K SLoC