mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
48a87c40cb
commit
a0d251ec8b
4 changed files with 46 additions and 13 deletions
|
|
@ -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<File>,
|
||||
|
|
@ -16,6 +16,7 @@ pub struct Scheduler {
|
|||
pub process: Arc<Process>,
|
||||
|
||||
micro: async_channel::Sender<BoxFuture<'static, ()>>,
|
||||
macro_: async_channel::Sender<TaskOp>,
|
||||
prog: mpsc::UnboundedSender<TaskProg>,
|
||||
pub running: Arc<RwLock<Running>>,
|
||||
}
|
||||
|
|
@ -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<BoxFuture<'static, ()>>) {
|
||||
fn schedule_macro(
|
||||
&self,
|
||||
micro: async_channel::Receiver<BoxFuture<'static, ()>>,
|
||||
macro_: async_channel::Receiver<TaskOp>,
|
||||
) {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,25 @@ impl From<&Task> for TaskSummary {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum TaskOp {
|
||||
File(Box<crate::workers::FileOp>),
|
||||
Plugin(Box<crate::workers::PluginOp>),
|
||||
Preload(Box<crate::workers::PreloadOp>),
|
||||
Process(Box<crate::workers::ProcessOp>),
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -16,10 +16,9 @@ pub struct Preload {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PreloadOpSize {
|
||||
pub id: usize,
|
||||
pub target: Url,
|
||||
pub throttle: Arc<Throttle<(Url, u64)>>,
|
||||
pub enum PreloadOp {
|
||||
Rule(PreloadOpRule),
|
||||
Size(PreloadOpSize),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -31,6 +30,13 @@ pub struct PreloadOpRule {
|
|||
pub targets: Vec<yazi_shared::fs::File>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PreloadOpSize {
|
||||
pub id: usize,
|
||||
pub target: Url,
|
||||
pub throttle: Arc<Throttle<(Url, u64)>>,
|
||||
}
|
||||
|
||||
impl Preload {
|
||||
pub fn new(prog: mpsc::UnboundedSender<TaskProg>) -> Self {
|
||||
Self { prog, rule_loaded: Default::default(), size_loading: Default::default() }
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ pub struct Process {
|
|||
prog: mpsc::UnboundedSender<TaskProg>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ProcessOp {
|
||||
Open(ProcessOpOpen),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ProcessOpOpen {
|
||||
pub id: usize,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue