ludic/ns-job.html
2026-09-17 22:10:03 +00:00

22 lines
No EOL
4.9 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Job — Ludic</title>
<meta name="description" content="Background work that stays out of the frame.">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="docs.css">
</head>
<body>
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
<main class="wrap item">
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <span class="here">Job</span></div>
<div class="item-head"><span class="kind-badge kind-namespace">namespace</span><h1 id="top">Job</h1></div>
<p class="ns-blurb">Background work that stays out of the frame. A <code>Job</code> is a future — a handle to a result that lands later. Kick one off with <code>Job.run</code> (a background compute that advances a little each <code>Job.pump</code> and finishes after enough frames, so heavy work never hitches) or <code>Job.defer</code> (a future you resolve yourself with <code>Job.fulfill</code> / <code>Job.fail</code>). Poll it with <code>done</code> / <code>ok</code> / <code>failed</code> / <code>cancelled</code>, read <code>result</code> / <code>error</code>, 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, <code>Job.parallel_for(count, fn work, ctx)</code> runs <code>work(i, ctx)</code> 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 <code>Job.*</code>.</p>
<div class="ns-methods"><a class="ns-method" href="job-defer.html"><code class="nm-sig">Job.defer() -&gt; Job</code><span class="nm-tip">A future you resolve yourself later.</span></a><a class="ns-method" href="job-run.html"><code class="nm-sig">Job.run(kind, arg) -&gt; Job</code><span class="nm-tip">Start a background compute job.</span></a><a class="ns-method" href="job-fulfill.html"><code class="nm-sig">Job.fulfill(handle, value) -&gt; void</code><span class="nm-tip">Resolve a pending job with a value.</span></a><a class="ns-method" href="job-fail.html"><code class="nm-sig">Job.fail(handle, error) -&gt; void</code><span class="nm-tip">Resolve a pending job as failed.</span></a><a class="ns-method" href="job-cancel.html"><code class="nm-sig">Job.cancel(handle) -&gt; void</code><span class="nm-tip">Cancel a job before it finishes.</span></a><a class="ns-method" href="job-pump.html"><code class="nm-sig">Job.pump(budget) -&gt; int</code><span class="nm-tip">Advance background jobs; collect results.</span></a><a class="ns-method" href="job-done.html"><code class="nm-sig">Job.done(handle) -&gt; bool</code><span class="nm-tip">Has the job resolved (any outcome)?</span></a><a class="ns-method" href="job-ok.html"><code class="nm-sig">Job.ok(handle) -&gt; bool</code><span class="nm-tip">Did the job succeed?</span></a><a class="ns-method" href="job-failed.html"><code class="nm-sig">Job.failed(handle) -&gt; bool</code><span class="nm-tip">Did the job fail?</span></a><a class="ns-method" href="job-cancelled.html"><code class="nm-sig">Job.cancelled(handle) -&gt; bool</code><span class="nm-tip">Was the job cancelled?</span></a><a class="ns-method" href="job-result.html"><code class="nm-sig">Job.result(handle) -&gt; int</code><span class="nm-tip">The success value of a done job.</span></a><a class="ns-method" href="job-error.html"><code class="nm-sig">Job.error(handle) -&gt; int</code><span class="nm-tip">The error code of a failed job.</span></a><a class="ns-method" href="job-pending.html"><code class="nm-sig">Job.pending() -&gt; int</code><span class="nm-tip">How many jobs are still unresolved.</span></a><a class="ns-method" href="job-free.html"><code class="nm-sig">Job.free(handle) -&gt; void</code><span class="nm-tip">Release a job slot back to the pool.</span></a><a class="ns-method" href="job-parallel_for.html"><code class="nm-sig">Job.parallel_for(count, work, ctx) -&gt; void</code><span class="nm-tip">Run work(i, ctx) for every i in [0, count) across all cores; returns when every call is done.</span></a><a class="ns-method" href="job-is_worker.html"><code class="nm-sig">Job.is_worker() -&gt; bool</code><span class="nm-tip">True on a Job.parallel_for pool thread, false on the main thread.</span></a></div>
<a class="back" href="api.html">← All symbols</a>
</main>
<script src="ludic-highlight.js"></script>
<script>Ludic.installCards(); Ludic.flashTarget();</script>
</body></html>