Skip to main content

Crate ashlar_jobs

Crate ashlar_jobs 

Source
Expand description

Background jobs: progress, cancel, panic isolation, apply-on-UI-thread.

A job runs on a worker thread with a snapshot of what it needs (moved in: an Arc of the document, a path…). It reports progress through Progress, stops when its CancelToken is cancelled, and runs under catch_unwind. It finishes with an Apply: a closure the UI thread runs on the app state when Jobs::drain_ready sees it (each frame, or when the wake hook asked for one). That is where the document is edited, as one undo step.

Jobs::list / Jobs::to_json describe every job for the progress panel and for agents. On wasm32 jobs run inline (no threads); long work there uses Jobs::spawn_stepped, which drain_ready advances a few steps per frame.

Structs§

CancelToken
Cooperative cancellation: the job checks it (or the bool its progress calls return).
JobBuilder
A job being described (Jobs::job): how it runs, then one of the spawn methods starts it.
JobId
A job’s id, unique within one Jobs.
JobInfo
One row of the progress panel / jobs.list.
JobRecord
A finished job (kept for the progress panel and agents).
Jobs
The background jobs of one app state S.
Progress
Handed to a running job: report progress, check for cancellation.
Ready
What Jobs::take_ready took: finished jobs and partial results, in order, to apply.
Updates
Sends partial results from a running job (JobBuilder::spawn_streaming): each one is applied on the UI thread by the next Jobs::drain_ready, in the order sent, while the job goes on (keyframes as a tracker finds them, hits as a search finds them). Updates sent before the job finished are applied even when it was cancelled; an update that fails to apply cancels its job, the failure becomes the job’s message and later updates are dropped.

Enums§

Status
Where a job is.
Step
What a stepped job’s step returns.

Functions§

apply
Box an apply closure.

Type Aliases§

Apply
What a finished job does to the app state, on the UI thread.
Wake
Called (from any thread) when a job has something to show: started, progressed, finished. Apps request a repaint here, so an idle app with no reporting jobs does no work.