q 0.1.1

Q is a Rust GDExtension crate for Godot, offering a Game Manager, Music Manager, Bevy ECS, and Tokio-powered multi-threading. It simplifies and enhances game development with efficient tools and scalable performance.
Documentation
use std::thread::{self, JoinHandle};

use crossbeam_channel::{Receiver, Sender};

pub fn spawn_worker<Req, Resp>(
    name: &str,
    rx: Receiver<Req>,
    tx: Sender<Resp>,
    handler: impl Fn(Req) -> Resp + Send + 'static,
) -> JoinHandle<()>
where
    Req: Send + 'static,
    Resp: Send + 'static,
{
    let thread_name = name.to_string();
    thread::Builder::new()
        .name(thread_name)
        .spawn(move || {
            while let Ok(request) = rx.recv() {
                let _ = tx.send(handler(request));
            }
        })
        .expect("Failed to spawn worker thread")
}