Result
Awaiting job results.
Awaiting job results.
const value = await queue.result(
id: string,
options?: { timeoutMs?: number; pollMs?: number },
): Promise<R>;Resolves with the task's return value once the job finishes. Rejects with
JobFailedError if the job fails or dead-letters, JobCancelledError if it
was cancelled, or ResultTimeoutError once the optional timeoutMs (default
30000) elapses before a terminal state is reached. pollMs (default 50) sets
the store poll interval.
const id = queue.enqueue("add", [2, 3]);
const sum = await queue.result(id); // 5
const sum2 = await queue.result(id, { timeoutMs: 5000 }); // throws on timeoutThe result is deserialized with the queue's serializer. Any process sharing the storage can await a result by id — the waiter polls the store.
| Method | Description |
|---|---|
getResult(id) → unknown | The deserialized result of a completed job, or undefined if there isn't one yet. Returns immediately — no polling, no rejection. |
getJob(id) → Job | null | The job's current state, or null for an unknown id. Its result is the raw Buffer the worker stored, before the serializer touches it. |
undefined is also what a job whose result TTL has expired looks like, and
what a dead or cancelled job looks like: neither produced a result. So it means
"no value to read", never "the job succeeded with nothing" — check
getJob(id)?.status when the difference matters.
The raw Buffer is the escape hatch, not the normal path. Reach for it to
re-encode a result under a different serializer, to forward bytes without
decoding them, or to inspect a payload a codec chain wrapped. Everything else
wants getResult(), which applies the same serializer the worker used to write
it — a mismatch there is what turns a working task into a decode error at the
reader.
result is for awaiting one job. To scan many jobs use
listJobs; for aggregate outcomes use
getMetrics.