Crate affair

source ·
Expand description

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::*;

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;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let socket = DedicatedThread::spawn(CounterWorker::default());
    assert_eq!(, 10);
    assert_eq!(, 13);


  • An executor that provides the worker with its dedicated std::thread.
  • A socket that can be used to communicate with a worker, you can use a socket to send requests to a worker and wait for the response.
  • An executor that runs the worker as a tokio task.
  • A weak reference to a Socket that does not keep the worker alive.



  • An awaiting worker that processes requests and returns a response.
  • An execution engine that handles spawning a Worker.
  • A non-awaiting worker that processes requests and returns a response.