• Wrap a function to get data, error and time in an array

    Type Parameters

    • Err = any
    • Fn extends ((...args) => any) = any

    Parameters

    • fn: Fn
    • Rest ...args: Parameters<Fn>

    Returns ReturnType<Fn> extends Promise<any>
        ? Promise<Response<Awaited<ReturnType<Fn>>, Err>>
        : Response<ReturnType<Fn>, Err>

    Example

    import { func, system } from "@rjweb/utils"

    const [ success, data, error, ms ] = func.wrap(system.execute, 'echo hi', { async: false })) // [true, 'hi\n', undefined, 1]
    const [ success, data, error, ms ] = func.wrap(system.execute, 'wesgasg', { async: false })) // [false, undefined, <Error>, 1]

    Since

    1.10.0

    Supports

    nodejs, browser