@nwire/queue
v0.7.1
Published
Nwire — queue transport contract + InMemory default + createQueueWorker. Production adapters land as @nwire/queue-bullmq, @nwire/queue-sqs, @nwire/queue-pgboss.
Readme
@nwire/queue
Background-job transport — queue contract + InMemory default + worker factory.
What it does
Defines a small QueueTransport interface (enqueue / consume / close) and ships an in-memory default for dev/tests that honors delayMs via setTimeout. createQueueWorker(app, transport, { subscribe }) binds named queues to Nwire actions so background jobs reuse the same handler shape as HTTP. Production deployments plug in @nwire/queue-bullmq (Redis); the contract is identical.
Install
pnpm add @nwire/queueQuick start
import { InMemoryQueueTransport, createQueueWorker } from "@nwire/queue";
const transport = new InMemoryQueueTransport();
const worker = createQueueWorker(app, transport, {
subscribe: [
{ queue: "emails", action: "sendWelcomeEmail" },
{ queue: "reports", action: "generateMonthlyReport", retry: { attempts: 3 } },
],
});
await transport.enqueue("emails", { userId: "u-1" });
await worker.start();
// worker pulls from "emails" → dispatches sendWelcomeEmail with the payloadAPI surface
QueueTransport— interface adapters implement.InMemoryQueueTransport— process-local default;delayMs-aware.createQueueWorker(app, transport, opts)— bind queues to actions.QueueMessage/QueueConsumer/QueueWorker/QueueSubscription/CreateQueueWorkerOptions— supporting types.
When to use
Whenever a request shouldn't block the caller — sending emails, building reports, syncing to a third party. Same handler shape as an HTTP action, so behavior is identical across transports.
Within nwire-app
For developers using this package as part of the Nwire stack — register it via app.use(...) or it auto-wires when you compose createApp({ modules }).
import { createApp } from "@nwire/forge";
const app = createApp({
/* ...config... */
});
// Adapter/plugin wiring happens here when applicable.