All files / app-leaderboard/src/http after-response.ts

71.42% Statements 5/7
50% Branches 1/2
50% Functions 1/2
80% Lines 4/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17                172x 172x   172x   172x      
import type { Context } from 'hono';
 
/**
 * Starts `work` after the response is sent (`waitUntil`). Without an execution context (tests calling `app.request`
 * directly) the work is not started at all: use it only for work a scheduled run also does.
 */
export function afterResponse(c: Context, work: () => Promise<unknown>): void {
  let context: { waitUntil(promise: Promise<unknown>): void } | undefined;
  try {
    context = c.executionCtx;
  } catch {
    context = undefined;
  }
  Eif (context === undefined) return;
  context.waitUntil(work().catch((error: unknown) => console.warn('background work failed', error)));
}