Skip to content

v0.12.0 — withBuckets() serverless flush

Choose a tag to compare

@VistaApps-za VistaApps-za released this 23 Jun 10:26
73d7ca6

withBuckets(handler) — keep the no-slip promise on serverless

The collector ships counts on a ~1/min timer — right for a long-lived server, wrong for serverless. Lambda / Cloud Functions / Cloud Run / Vercel freeze the container the instant a handler returns, so a sub-minute invocation's counted reads are billed by the provider but never shipped. withBuckets() closes that blind spot.

import { withBuckets } from "@cross-deck/buckets";
export const handler = withBuckets(async (event) => { /* …db reads… */ });
export const handler = withBuckets("nightly-export", async (event) => { /* … */ });
  • Flushes the meter once, in a finally, before the function returns — on success and on throw.
  • Transparent: forwards args + this, returns/throws unchanged.
  • A flush fault can never escape into the caller; fails fast on misuse.
  • Fully typed; 7 new tests; 45/45 suite green.