ViteHub

Queue

Enqueue background work from Vite and Nitro with one portable API and provider-managed delivery.

@vitehub/queue gives Vite and Nitro apps one way to define background job handlers, enqueue work from request code, and deliver those jobs through Cloudflare Queues or Vercel Queue.

Use Queue when the request should return before the work finishes. The application keeps a small typed enqueue call. The provider handles delivery, retry behavior, and callback execution.

import { runQueue } from '@vitehub/queue'
import type { WelcomeEmailPayload } from '../queues/welcome-email'

export default defineEventHandler(async (event) => {
  const payload = await readBody<WelcomeEmailPayload>(event)
  const result = await runQueue('welcome-email', payload)

  return { ok: true, result }
})

What Queue solves

Inline request work is the simplest option until the work can happen after the response, needs provider-managed retry, or should move behind a named background boundary.

Queue moves that work behind a discovered definition:

Fast request paths

Enqueue a job and return an application response without waiting for the handler to finish.

Portable producers

Keep runQueue() and deferQueue() calls the same while provider setup stays in framework config.

Provider delivery

Use Cloudflare or Vercel queue infrastructure for delivery, delayed sends, callbacks, and retries.

Discovered handlers

Let ViteHub find queue files and generate the runtime registry for the active framework.

One portable flow

The same shape works across providers:

  1. Register the Vite plugin or Nitro module.
  2. Choose cloudflare or vercel in queue.provider.
  3. Define a named queue with defineQueue().
  4. Enqueue work with runQueue(name, payload).
  5. Use deferQueue(name, payload) when dispatch can happen after the response.
Provider-specific setup belongs in app config and deployment output. Queue definitions and producer calls should stay provider-neutral whenever possible.

Discovery model

Vite discovers queue definitions from src/**/*.queue.ts.

The queue name comes from the path under src, without the .queue suffix. src/email/welcome.queue.ts becomes email/welcome.

Supported providers

Cloudflare
Use Cloudflare Queues with generated producer bindings and batch consumers.
Vercel
Use Vercel Queue with generated topics and hosted callback functions.

Start here

Start with Quickstart for the smallest complete setup. Use the primitive comparison when you are deciding between KV, Blob, Queue, Sandbox, or inline request code.

Next steps

Quickstart
Define a welcome-email queue and enqueue it from a route.
Usage
Use typed jobs, enqueue envelopes, deferred dispatch, and provider clients.
Runtime API
Review exports, signatures, options, and provider-specific helpers.
Troubleshooting
Fix unknown queues, missing bindings, Vercel regions, and unsupported options.
Copyright © 2026