diff --git a/yazi-scheduler/src/scheduler.rs b/yazi-scheduler/src/scheduler.rs index 5773f1fc..fe59b399 100644 --- a/yazi-scheduler/src/scheduler.rs +++ b/yazi-scheduler/src/scheduler.rs @@ -7,7 +7,7 @@ use yazi_config::{open::Opener, plugin::PluginRule, TASKS}; use yazi_shared::{emit, event::Exec, fs::{unique_path, Url}, Layer, Throttle}; use super::{Running, TaskProg, TaskStage}; -use crate::{workers::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash, Plugin, PluginOpEntry, Preload, PreloadOpRule, PreloadOpSize, Process, ProcessOpOpen}, TaskKind}; +use crate::{workers::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash, Plugin, PluginOpEntry, Preload, PreloadOpRule, PreloadOpSize, Process, ProcessOpOpen}, TaskKind, TaskOp}; pub struct Scheduler { pub file: Arc, @@ -16,6 +16,7 @@ pub struct Scheduler { pub process: Arc, micro: async_channel::Sender>, + macro_: async_channel::Sender, prog: mpsc::UnboundedSender, pub running: Arc>, } @@ -23,6 +24,7 @@ pub struct Scheduler { impl Scheduler { pub fn start() -> Self { let (micro_tx, micro_rx) = async_channel::unbounded(); + let (macro_tx, macro_rx) = async_channel::unbounded(); let (prog_tx, prog_rx) = mpsc::unbounded_channel(); let scheduler = Self { @@ -32,6 +34,7 @@ impl Scheduler { process: Arc::new(Process::new(prog_tx.clone())), micro: micro_tx, + macro_: macro_tx, prog: prog_tx, running: Default::default(), }; @@ -40,7 +43,7 @@ impl Scheduler { scheduler.schedule_micro(micro_rx.clone()); } for _ in 0..TASKS.macro_workers { - scheduler.schedule_macro(micro_rx.clone()); + scheduler.schedule_macro(micro_rx.clone(), macro_rx.clone()); } scheduler.progress(prog_rx); scheduler @@ -56,7 +59,11 @@ impl Scheduler { }); } - fn schedule_macro(&self, rx: async_channel::Receiver>) { + fn schedule_macro( + &self, + micro: async_channel::Receiver>, + macro_: async_channel::Receiver, + ) { let file = self.file.clone(); let plugin = self.plugin.clone(); @@ -65,15 +72,11 @@ impl Scheduler { tokio::spawn(async move { loop { - if let Ok(fut) = rx.try_recv() { - fut.await; - continue; - } - select! { - Ok(fut) = rx.recv() => { + Ok(fut) = micro.recv() => { fut.await; } + Ok(op) = macro_.recv() => {} Ok((id, mut op)) = file.recv() => { if !running.read().exists(id) { continue; diff --git a/yazi-scheduler/src/task.rs b/yazi-scheduler/src/task.rs index 27baceea..3a57ab22 100644 --- a/yazi-scheduler/src/task.rs +++ b/yazi-scheduler/src/task.rs @@ -58,6 +58,25 @@ impl From<&Task> for TaskSummary { } } +#[derive(Debug)] +pub enum TaskOp { + File(Box), + Plugin(Box), + Preload(Box), + Process(Box), +} + +impl TaskOp { + pub fn id(&self) { + match self { + TaskOp::File(op) => todo!(), + TaskOp::Plugin(op) => todo!(), + TaskOp::Preload(_) => todo!(), + TaskOp::Process(_) => todo!(), + } + } +} + #[derive(Debug)] pub enum TaskProg { // id, size diff --git a/yazi-scheduler/src/workers/preload.rs b/yazi-scheduler/src/workers/preload.rs index 5a22bf5e..db801e9e 100644 --- a/yazi-scheduler/src/workers/preload.rs +++ b/yazi-scheduler/src/workers/preload.rs @@ -16,10 +16,9 @@ pub struct Preload { } #[derive(Debug)] -pub struct PreloadOpSize { - pub id: usize, - pub target: Url, - pub throttle: Arc>, +pub enum PreloadOp { + Rule(PreloadOpRule), + Size(PreloadOpSize), } #[derive(Clone, Debug)] @@ -31,6 +30,13 @@ pub struct PreloadOpRule { pub targets: Vec, } +#[derive(Debug)] +pub struct PreloadOpSize { + pub id: usize, + pub target: Url, + pub throttle: Arc>, +} + impl Preload { pub fn new(prog: mpsc::UnboundedSender) -> Self { Self { prog, rule_loaded: Default::default(), size_loading: Default::default() } diff --git a/yazi-scheduler/src/workers/process.rs b/yazi-scheduler/src/workers/process.rs index acba196b..8665dcf3 100644 --- a/yazi-scheduler/src/workers/process.rs +++ b/yazi-scheduler/src/workers/process.rs @@ -10,6 +10,11 @@ pub struct Process { prog: mpsc::UnboundedSender, } +#[derive(Debug)] +pub enum ProcessOp { + Open(ProcessOpOpen), +} + #[derive(Debug)] pub struct ProcessOpOpen { pub id: usize,