👕 refactor

main
_ 2023-09-09 10:30:53 -05:00
parent 1acd125fdd
commit 6ef12c5859
1 changed files with 17 additions and 6 deletions

View File

@ -20,10 +20,15 @@ fn main() -> Result <(), TaskError>
Ok (())
}
struct Driver <'a>
struct ThreadSystem <'a>
{
pool: &'a ThreadPool,
send: mpsc::SyncSender <TaskOutput>,
}
struct Driver <'a>
{
thread_sys: ThreadSystem <'a>,
recv: mpsc::Receiver <TaskOutput>,
ctl: Controller,
@ -39,10 +44,15 @@ impl <'a> Driver <'_>
{
let (send, recv) = mpsc::sync_channel (8);
Driver
let thread_sys = ThreadSystem
{
pool,
send,
};
Driver
{
thread_sys,
recv,
ctl: Default::default (),
@ -114,14 +124,15 @@ impl <'a> Driver <'_>
let dur_encode = Duration::from_millis (20);
let dur_transmit = Duration::from_millis (200);
let send = self.send.clone ();
let pool = &self.thread_sys.pool;
let send = self.thread_sys.send.clone ();
match event
{
TxPipelineEvent::Capture => {
let cap = self.capture.start (())?;
self.pool.spawn (move ||
pool.spawn (move ||
{
thread::sleep (dur_capture);
let buf_raw = BufRaw
@ -151,7 +162,7 @@ impl <'a> Driver <'_>
{
let mut encoder = self.encoder.start (EncoderTaskMetadata {})?;
self.pool.spawn (move ||
pool.spawn (move ||
{
thread::sleep (dur_encode);
encoder.try_handle_insert_data (&buf_raw.buf).unwrap ();
@ -160,7 +171,7 @@ impl <'a> Driver <'_>
},
TxPipelineEvent::Transmit (_buf_enc) => {
let tx = self.transmitter.start (())?;
self.pool.spawn (move ||
pool.spawn (move ||
{
thread::sleep (dur_transmit);
send.send (TaskOutput::TxTransmit ((tx, false))).unwrap ();