pub fn new(state: State, channel_size: usize, name: String) -> Self {
        let (in_sender, in_receiver) = bounded::<Input>(channel_size);
        let (out_sender, out_receiver) = bounded::<Output>(channel_size);

        std::thread::spawn(move || { // TODO: debug timing
            let mut state = state;
            let mut timing = AverageTimeCounter::new();
            while let Ok(input) = in_receiver.recv() {
                // Compute
                let t1 = Instant::now();
                let output = state.compute(input);
                let t2 = Instant::now();
                timing.add_time(t2 - t1);

                // Send debug info
                send_worker_perf("Workers", &name, &name, timing.average_time_micros() as f32, timing.average_iter_per_sec(), 0);

                // Send result
                match out_sender.send(output) {
                    Ok(()) => (),
                    Err(_) => break,
                }
            }
        });

        Self {
            to_worker: in_sender,
            from_worker: out_receiver,
            _phantom: PhantomData,
        }
    }
/// Start a new worker with the given state using the provided channel size. The name is used for debug printing.
Start a new worker with the given state using the provided channel size. The name is used for debug printing.
Start a new worker with the given state using the provided channel size . The name is used for debug printing .
pub fn new(state: State, channel_size: usize, name: String) -> Self {
        let (in_sender, in_receiver) = bounded::<Input>(channel_size);
        let (out_sender, out_receiver) = bounded::<Output>(channel_size);
        std::thread::spawn(move || { // TODO: debug timing
            let mut state = state;
            let mut timing = AverageTimeCounter::new();
            while let Ok(input) = in_receiver.recv() {
                // Compute
                let t1 = Instant::now();
                let output = state.compute(input);
                let t2 = Instant::now();
                timing.add_time(t2 - t1);
                // Send debug info
                send_worker_perf("Workers", &name, &name, timing.average_time_micros() as f32, timing.average_iter_per_sec(), 0);
                // Send result
                match out_sender.send(output) {
                    Ok(()) => (),
                    Err(_) => break,
                }
            }
        });
        Self {
            to_worker: in_sender,
            from_worker: out_receiver,
            _phantom: PhantomData,
        }
    }
pub fn new ( state : State , channel_size : usize , name : String ) -> Self { let ( in_sender , in_receiver ) = bounded :: < Input > ( channel_size ) ; let ( out_sender , out_receiver ) = bounded :: < Output > ( channel_size ) ; std :: thread :: spawn ( move | | { // TODO: debug timing let mut state = state ; let mut timing = AverageTimeCounter :: new ( ) ; while let Ok ( input ) = in_receiver . recv ( ) { // Compute let t1 = Instant :: now ( ) ; let output = state . compute ( input ) ; let t2 = Instant :: now ( ) ; timing . add_time ( t2 - t1 ) ; // Send debug info send_worker_perf ( " " , & name , & name , timing . average_time_micros ( ) as f32 , timing . average_iter_per_sec ( ) , 0 ) ; // Send result match out_sender . send ( output ) { Ok ( ( ) ) => ( ) , Err ( _ ) => break , } } } ) ; Self { to_worker : in_sender , from_worker : out_receiver , _phantom : PhantomData , } }
Start a new worker with the given state using the provided channel size.
Start a new worker with the given state using the provided channel size .
state
State
channel_size
usize
name
String
state
State
channel_size
usize
name
String