Crates.io | affair |
lib.rs | affair |
version | 0.1.2 |
source | src |
created_at | 2023-05-09 16:11:28.058793 |
updated_at | 2023-07-29 19:13:16.039533 |
description | A Tokio-based worker abstraction layer. |
homepage | |
repository | https://github.com/fleek-network/lightning |
max_upload_size | |
id | 860659 |
size | 25,319 |
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.
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);
}