notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 3f2f39678947f22d58666416b0e14f999abdd367
parent 3cac808791d191f6c7081e5f207109e94b2945fe
Author: kernelkind <kernelkind@gmail.com>
Date:   Tue, 28 Oct 2025 16:39:15 -0400

feat(jobs): add `schedule_receivable`

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck/src/jobs/job_pool.rs | 21+++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/crates/notedeck/src/jobs/job_pool.rs b/crates/notedeck/src/jobs/job_pool.rs @@ -1,6 +1,6 @@ use crossbeam::channel; use std::future::Future; -use tokio::sync::oneshot::{self}; +use tokio::sync::oneshot::{self, Receiver}; type Job = Box<dyn FnOnce() + Send + 'static>; @@ -36,6 +36,19 @@ impl JobPool { F: FnOnce() -> T + Send + 'static, T: Send + 'static, { + let rx_result = self.schedule_receivable(job); + async move { + rx_result.await.unwrap_or_else(|_| { + panic!("Worker thread or channel dropped before returning the result.") + }) + } + } + + pub fn schedule_receivable<F, T>(&self, job: F) -> Receiver<T> + where + F: FnOnce() -> T + Send + 'static, + T: Send + 'static, + { let (tx_result, rx_result) = oneshot::channel::<T>(); let job = Box::new(move || { @@ -45,11 +58,7 @@ impl JobPool { self.push_job(job); - async move { - rx_result.await.unwrap_or_else(|_| { - panic!("Worker thread or channel dropped before returning the result.") - }) - } + rx_result } pub fn schedule_no_output(&self, job: impl FnOnce() + Send + 'static) {