commit 28c364c4b162eb3b95bfa8f810169f1c1167a57d
parent a7074636883b023d7b4604cb426e56c94151199c
Author: kernelkind <kernelkind@gmail.com>
Date: Fri, 21 Nov 2025 13:40:34 -0700
feat(jobs): structs for new JobCache
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
2 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/crates/notedeck/src/jobs/mod.rs b/crates/notedeck/src/jobs/mod.rs
@@ -1,6 +1,10 @@
mod cache_old;
mod job_pool;
+pub(crate) mod types;
+pub use crate::jobs::types::{
+ CompleteResponse, JobOutput, JobPackage, JobRun, NoOutputRun, RunType,
+};
pub use cache_old::{
BlurhashParams, Job, JobError, JobIdOld, JobParams, JobParamsOwned, JobState, JobsCacheOld,
};
diff --git a/crates/notedeck/src/jobs/types.rs b/crates/notedeck/src/jobs/types.rs
@@ -0,0 +1,100 @@
+use std::{future::Future, pin::Pin};
+
+pub enum JobOutput<T> {
+ Complete(CompleteResponse<T>),
+ Next(JobRun<T>),
+}
+
+impl<T> JobOutput<T> {
+ pub fn complete(response: T) -> Self {
+ JobOutput::Complete(CompleteResponse::new(response))
+ }
+}
+
+pub struct CompleteResponse<T> {
+ pub(crate) response: T,
+ pub(crate) run_no_output: Option<NoOutputRun>,
+}
+
+pub struct JobComplete<K, T> {
+ pub job_id: JobId<K>,
+ pub response: T,
+}
+
+impl<T> CompleteResponse<T> {
+ pub fn new(response: T) -> Self {
+ Self {
+ response,
+ run_no_output: None,
+ }
+ }
+
+ pub fn run_no_output(mut self, run: NoOutputRun) -> Self {
+ self.run_no_output = Some(run);
+ self
+ }
+}
+
+pub enum NoOutputRun {
+ Sync(Box<dyn FnOnce() + Send + 'static>),
+ Async(Pin<Box<dyn Future<Output = ()> + Send + 'static>>),
+}
+
+pub(crate) type SyncJob<T> = Box<dyn FnOnce() -> JobOutput<T> + Send + 'static>;
+pub(crate) type AsyncJob<T> = Pin<Box<dyn Future<Output = JobOutput<T>> + Send + 'static>>;
+
+pub enum JobRun<T> {
+ Sync(SyncJob<T>),
+ Async(AsyncJob<T>),
+}
+
+pub struct JobPackage<K, T> {
+ pub(crate) id: JobIdAccessible<K>,
+ pub(crate) run: RunType<T>,
+}
+
+impl<K, T> JobPackage<K, T> {
+ pub fn new(id: String, job_kind: K, run: RunType<T>) -> Self {
+ Self {
+ id: JobIdAccessible::new_public(id, job_kind),
+ run,
+ }
+ }
+}
+
+pub enum RunType<T> {
+ NoOutput(NoOutputRun),
+ Output(JobRun<T>),
+}
+
+#[derive(Debug, PartialEq, Eq, Clone, Hash)]
+pub struct JobId<K> {
+ pub id: String,
+ pub job_kind: K,
+}
+
+#[derive(Debug, PartialEq, Eq, Clone, Hash)]
+pub(crate) enum JobAccess {
+ Public, // Jobs requested outside the cache
+ Internal, // Jobs requested inside the cache
+}
+
+#[derive(Debug, PartialEq, Eq, Clone, Hash)]
+pub(crate) struct JobIdAccessible<K> {
+ pub access: JobAccess,
+ pub job_id: JobId<K>,
+}
+
+impl<K> JobIdAccessible<K> {
+ pub fn new_public(id: String, job_kind: K) -> Self {
+ Self {
+ job_id: JobId { id, job_kind },
+ access: JobAccess::Public,
+ }
+ }
+
+ pub fn into_internal(mut self) -> Self {
+ self.access = JobAccess::Internal;
+ self
+ }
+}