From 7130eafc066275f45a8464cd546acc23f5bae3db Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 19 Oct 2023 14:55:24 -0700 Subject: [PATCH] implement QNWorker --- src/worker.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/worker.rs b/src/worker.rs index 3d3862d..65e9d66 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -85,6 +85,41 @@ impl QRWorker{ } } +/* +QN = WorkerDescription{ + input:Queued, + output:None(Single), +} +*/ +//None Output Worker does all its work internally from the perspective of the work submitter +pub struct QNWorker { + sender: mpsc::Sender, +} + +impl QNWorker{ + pub fn new(mut f:F)->Self{ + let (sender,receiver)=mpsc::channel::(); + let ret=Self { + sender, + }; + thread::spawn(move ||{ + loop { + match receiver.recv() { + Ok(task)=>f(task), + Err(_)=>{ + println!("Worker stopping.",); + break; + } + } + } + }); + ret + } + pub fn send(&self,task:Task)->Result<(),mpsc::SendError>{ + self.sender.send(task) + } +} + pub struct CompatCRWorker{ data:std::marker::PhantomData, f:F, @@ -114,7 +149,7 @@ implValue> CompatCRWorker{ fn test_worker() { println!("hiiiii"); // Create the worker thread - let worker=CRWorker::new(crate::physics::Body::with_pva(crate::integer::Planar64Vec3::ZERO,crate::integer::Planar64Vec3::ZERO,crate::integer::Planar64Vec3::ZERO), + let worker=QRWorker::new(crate::physics::Body::with_pva(crate::integer::Planar64Vec3::ZERO,crate::integer::Planar64Vec3::ZERO,crate::integer::Planar64Vec3::ZERO), |_|crate::physics::Body::with_pva(crate::integer::Planar64Vec3::ONE,crate::integer::Planar64Vec3::ONE,crate::integer::Planar64Vec3::ONE) );