mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
27 lines
774 B
Rust
27 lines
774 B
Rust
use anyhow::{Result, anyhow};
|
|
use tokio::sync::mpsc;
|
|
use yazi_core::tasks::TaskOpt;
|
|
use yazi_macro::{emit, relay};
|
|
use yazi_scheduler::process::ShellOpt;
|
|
use yazi_shared::id::Id;
|
|
|
|
pub struct TasksProxy;
|
|
|
|
impl TasksProxy {
|
|
pub async fn spawn(opt: TaskOpt) -> Result<Id> {
|
|
let (tx, mut rx) = mpsc::unbounded_channel();
|
|
emit!(Call(relay!(tasks:spawn).with_any("opt", opt).with_replier(tx)));
|
|
|
|
rx.recv().await.ok_or_else(|| anyhow!("channel closed"))??.try_into()
|
|
}
|
|
|
|
pub fn process_open(opt: ShellOpt) {
|
|
emit!(Call(relay!(tasks:process_open).with_any("opt", opt)));
|
|
}
|
|
|
|
pub async fn process_exec(opt: ShellOpt) {
|
|
let (tx, mut rx) = mpsc::unbounded_channel();
|
|
emit!(Call(relay!(tasks:process_open).with_any("opt", opt).with_replier(tx)));
|
|
rx.recv().await;
|
|
}
|
|
}
|