Skip to content

Commit

Permalink
Use crossbeam_channel instead of std::sync::mpsc.
Browse files Browse the repository at this point in the history
Slightly speedup things (even if not a lot compared to full use case)
  • Loading branch information
mgautierfr committed Apr 29, 2024
1 parent 0685afe commit f0f13bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ categories = ["concurrency", "data-structures"]


[dependencies]
crossbeam-channel = "0.5.12"

7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,17 @@ impl<T: Send + 'static> Clone for Dropper<T> {
}

mod inner {
use std::{sync::mpsc, thread};
use crossbeam_channel::{unbounded, Sender};
use std::thread;

pub struct Dropper<T: Send> {
drop_sender: Option<mpsc::Sender<T>>,
drop_sender: Option<Sender<T>>,
thread_handle: Option<thread::JoinHandle<()>>,
}

impl<T: Send + 'static> Dropper<T> {
pub fn new() -> Self {
let (drop_sender, drop_receiver) = mpsc::channel();
let (drop_sender, drop_receiver) = unbounded();
let thread_handle = thread::Builder::new()
.name("Dropout".into())
.spawn(move || while let Ok(_) = drop_receiver.recv() {})
Expand Down

0 comments on commit f0f13bc

Please sign in to comment.