lapin icon indicating copy to clipboard operation
lapin copied to clipboard

A cleaner way to limit tokio spawn than a tokio::sync::Semaphore

Open doubleailes opened this issue 1 month ago • 0 comments

Hello,

I would like to limit the number of spawn thread when using tokio executor.

I end up using

 let semaphore = Arc::new(Semaphore::new(32));
    consumer.set_delegate(move |delivery: DeliveryResult| {
        let semaphore_clone = Arc::clone(&semaphore);
        async move {
            let _permit = semaphore_clone.acquire().await;
        ....}

Is there a cleaner to deal with it?

doubleailes avatar May 27 '24 09:05 doubleailes