API Reference › Job
namespace

Job

Background work that stays out of the frame. A Job is a future — a handle to a result that lands later. Kick one off with Job.run (a background compute that advances a little each Job.pump and finishes after enough frames, so heavy work never hitches) or Job.defer (a future you resolve yourself with Job.fulfill / Job.fail). Poll it with done / ok / failed / cancelled, read result / error, and always collect on the main thread — a Job must never touch the ECS world directly. The scheduler is deterministic and cooperative, so the same jobs and the same budget reproduce byte-for-byte, every run and every target. For work that should use every core now, Job.parallel_for(count, fn work, ctx) runs work(i, ctx) across a pool of real OS threads and returns when all of it is done; a worker computes on what it was handed and never changes the world. Arguments are positional. Spliced in only when a program mentions Job.*.

Job.defer() -> JobA future you resolve yourself later.Job.run(kind, arg) -> JobStart a background compute job.Job.fulfill(handle, value) -> voidResolve a pending job with a value.Job.fail(handle, error) -> voidResolve a pending job as failed.Job.cancel(handle) -> voidCancel a job before it finishes.Job.pump(budget) -> intAdvance background jobs; collect results.Job.done(handle) -> boolHas the job resolved (any outcome)?Job.ok(handle) -> boolDid the job succeed?Job.failed(handle) -> boolDid the job fail?Job.cancelled(handle) -> boolWas the job cancelled?Job.result(handle) -> intThe success value of a done job.Job.error(handle) -> intThe error code of a failed job.Job.pending() -> intHow many jobs are still unresolved.Job.free(handle) -> voidRelease a job slot back to the pool.Job.parallel_for(count, work, ctx) -> voidRun work(i, ctx) for every i in [0, count) across all cores; returns when every call is done.Job.is_worker() -> boolTrue on a Job.parallel_for pool thread, false on the main thread.
← All symbols