Aller au contenu principal

around()

around<In, Out>(wrapper): Decorator<In, Out>

Creates a decorator with full control over execution. The wrapper receives both the original function and the input, and decides how (or whether) to call it. This is the most powerful form - before and after are special cases of around.


Type Parameters

In: In

The input type

Out: Out

The output type


Parameters

wrapper: (fn, input) => Out

Function that controls execution


Returns: Decorator<In, Out>

A Decorator


Since

2.4.0


Example

// Retry decorator
const withRetry = around<string, Response>((fn, input) => {
try { return fn(input); }
catch { return fn(input); } // one retry
});

// Caching decorator
const cache = new `Map<string, Data>`();
const withCache = around<string, Data>((fn, key) => {
const cached = cache.get(key);
if (cached) return cached;
const result = fn(key);
cache.set(key, result);
return result;
});