Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
8 replies
jack

wrapping a generic function in typescript

i'm trying to write a wrapper to automatically handle loading state when necessary. my idea is to wrap my function definitions in this function busyable which then returns a function that precedes and succeeds the callback passed in by toggling busy state. something like this:
    const busyable = (fn: (...args: any) => Promise<void>) => {
        return async (...args: any) => {
            busy = true;
            await fn(...args);
            busy = false;
        };
    };


something is off (likely function parameters), and it seems like my function might be getting run twice. any help is appreciated.
Was this page helpful?