Skip to content

Worker client ​

createDungeon(request, opts?) uses one shared client. For your own instance:

js
import { createDungeonMaker } from 'dungeonmaker-js';

const maker = createDungeonMaker({ timeout: 10_000 });
await maker.ready(); // optional warm-up
const dungeon = await maker.create({ design, seed: 7 }, { signal: AbortSignal.timeout(5_000) });
maker.dispose();

Options of createDungeonMaker:

OptionDefaultMeaning
workerbundledFactory returning a Worker (WorkerLike); see Bundlers.
wasmUrlbundledURL of dungeonmaker.wasm. Relative strings resolve against the page URL.
timeout30_000Milliseconds per request; Infinity disables it, otherwise 1 … 2147483647.
validatefalseCheck the design with the schema validator first (loaded lazily).
  • The worker starts on first use. Requests run one at a time, in order (FIFO). With validate: true a config request joins the queue only after its validation, so a legacy-text request made later can overtake it.
  • The timeout counts from dispatch to the worker. For the first request it includes worker start.
  • The design is snapshotted when create() is called; later changes to the object have no effect.
  • ready() starts the worker early and rejects with TimeoutError after timeout.
  • dispose() terminates the worker and rejects pending requests with an AbortError.
  • Per call: { signal, timeout }. The seed is 1 … 2³²−1; omitted, a random one is drawn.

Errors ​

Every failure of create(), createDungeon() and ready() arrives as a rejection, never as a promise that hangs.

ErrorCause
DesignValidationErrorThe design cannot run; issues carry JSON Pointer paths.
GenerationErrorThe library hit an internal assert. The worker recovers.
TimeoutErrorThe request exceeded timeout. The worker restarts on the next call.
RangeErrorInvalid seed or timeout (an invalid timeout for createDungeonMaker throws right away).
DataCloneErrorThe design object cannot be structured-cloned (it holds a function or a symbol); a DOMException.
WorkerErrorThe worker could not start, crashed or speaks another protocol: a bundler or CSP problem, not the design.
signal.reasonThe call was aborted; by default an AbortError DOMException.

Error classes are exported from dungeonmaker-js; see the API reference for their members.

DungeonMaker 2.05 © Peter Henningsen. WebAssembly port, package and site created by spearwolf. Released under GPL-3.0-or-later. About · License