/** * Deferred execution abstraction - framework agnostic * * Provides a way to schedule work to run after the current operation completes. * Different frameworks can provide their own implementations: * - Next.js: uses `after()` from `next/server` * - Generic: uses `setImmediate()` or `setTimeout()` * - Testing: can use synchronous execution */ /** * Interface for deferred execution * * Implementations should schedule the function to run asynchronously * without blocking the current operation. */ interface DeferredExecutor { /** * Schedule a function to run asynchronously * * The function should be executed after the current operation completes. * Errors should be caught and logged, not propagated. * * @param fn - Async function to execute */ defer(fn: () => Promise): void; } /** * Generic deferred executor using setImmediate/setTimeout * * Works in Node.js and browser environments. * Suitable for non-framework environments or testing. */ declare const genericDeferred: DeferredExecutor; /** * Synchronous deferred executor * * Executes the function immediately (fire-and-forget). * Useful for testing or when deferred execution isn't needed. */ declare const synchronousDeferred: DeferredExecutor; /** * Create a custom deferred executor * * Allows frameworks to provide their own scheduling mechanism. * * @example * ```typescript * // Next.js adapter * import { after } from 'next/server'; * * const nextJsDeferred = createDeferredExecutor((fn) => after(fn)); * ``` * * @param schedule - Function that schedules async work * @returns DeferredExecutor instance */ declare function createDeferredExecutor(schedule: (fn: () => Promise) => void): DeferredExecutor; /** * No-op deferred executor * * Discards deferred work. Useful when you want to disable * background tasks (e.g., in certain test scenarios). */ declare const noopDeferred: DeferredExecutor; export { type DeferredExecutor as D, createDeferredExecutor as c, genericDeferred as g, noopDeferred as n, synchronousDeferred as s };