#actor #channel #tokio #async

atticus

A mimimal API to create asynchronous actors

6 releases

0.3.0 Apr 18, 2024
0.2.2 Apr 3, 2024
0.2.1 Mar 28, 2024
0.2.0 Jul 12, 2023
0.1.0 May 3, 2023

#291 in Asynchronous

Download history 232/week @ 2024-01-04 164/week @ 2024-01-11 108/week @ 2024-01-18 111/week @ 2024-01-25 242/week @ 2024-02-01 158/week @ 2024-02-08 272/week @ 2024-02-15 258/week @ 2024-02-22 182/week @ 2024-02-29 159/week @ 2024-03-07 401/week @ 2024-03-14 404/week @ 2024-03-21 1296/week @ 2024-03-28 413/week @ 2024-04-04 267/week @ 2024-04-11 279/week @ 2024-04-18

2,435 downloads per month

MIT/Apache

13KB
158 lines

atticus: A simple implementation of an actor in tokio.

build crates.io Crates.io Downloads (recent)

Actors provide a way to invoke messages or requests among asynchronous tasks. This avoids the need to use Arc<Mutex<T>> instances of an object to be passed around so shared state can be made. It makes use of channels to exchange data.

Actors aim to clarify ownership data structures.

Objective

The main objective of this library is to provide the most basic or minimal implementation of an actor that can in the tokio runtime.

There may be future endeavors to make it run in other runtimes as well as no_std support.

Usage

Create an actor by implementing the Actor trait.

use atticus::{Actor, actor};
use async_trait::async_trait;

struct IntToString;

#[async_trait]
impl Actor for IntToString {
    type Request = i32;
    type Response = String;
    async fn handle(&mut self, request: Self::Request) -> Option<Self::Response> {
        Some(request.to_string())
    }
}

#[tokio::main(flavor="current_thread")]
async fn main() {
    // Spawn the actor
    let handle = actor::run(IntToString{}, 1);

    // Send a request to convert 5 to String.
    let response = handle.requestor.request(5).await;

    assert!(response.is_ok());
    assert_eq!(response.unwrap(), Some(String::from("5")));
}

License

This project is licensed under either of

at your option.

The SPDX license identifier for this project is MIT OR Apache-2.0.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2.3–4MB
~65K SLoC