Long-Running Operations

Google API Improvement Proposals AIP-151 (Long-Running Operations) — a uniform shape for async APIs where the response can't be computed within the request lifetime. The operator's POST endpoint returns an Operation resource (name / done / metadata / response | error) which the client polls at /operations/ until done: true. Composes existing b.queue / b.jobs for the actual work; this module just ships the wire-shape + status-poll endpoint helpers.

b.lro.create(opts) returns { submit, status, list, cancel } wired to operator-supplied storage (in-memory by default for single-process; ops with multiple workers wire b.cache / b.db storage via opts.store).

b.lro.create(opts?) #

stable0.10.16
{
  store:        Map-like { get, set, delete, keys },
  namePrefix:   string, // default "operations/"
  maxConcurrent: number, // soft cap; overflow refuses with lro/too-many
}

Create an LRO registry. Returns { submit, status, list, cancel }. Operations are tracked in opts.store (a Map-shaped object) or an in-memory Map when omitted. submit({ work, metadata?, name? }) runs work async + returns the initial Operation resource; status(name) returns the current Operation (with done: true + response or error set when finished); cancel(name) surfaces cancellation back to the work function via the supplied AbortSignal.

var lro = b.lro.create();
var op = await lro.submit({
  work: async function (signal) { return await heavyJob(signal); },
});
res.statusCode = 202;
res.end(JSON.stringify(op));

// Later, on GET /operations/:
res.end(JSON.stringify(lro.status(op.name)));

Last updated 2026-08-08T16:39:49.652Z by seeder.