affair

Crates.ioaffair
lib.rsaffair
version0.1.2
sourcesrc
created_at2023-05-09 16:11:28.058793
updated_at2023-07-29 19:13:16.039533
descriptionA Tokio-based worker abstraction layer.
homepage
repositoryhttps://github.com/fleek-network/lightning
max_upload_size
id860659
size25,319
Parsa (qti3e)

documentation

README

Affair

A simple tokio-based library to spawn a worker and communicate with it, the worker can be spawned on a dedicated thread or as a tokio task.

Example

use affair::*;

#[derive(Default)]
struct CounterWorker {
    current: u64,
}

impl Worker for CounterWorker {
    type Request = u64;
    type Response = u64;

    fn handle(&mut self, req: Self::Request) -> Self::Response {
        self.current += req;
        self.current
    }
}

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let port = DedicatedThread::spawn(CounterWorker::default());
    assert_eq!(port.run(10).await.unwrap(), 10);
    assert_eq!(port.run(3).await.unwrap(), 13);
}
Commit count: 1355

cargo fmt