@eroyeroy/utils - v0.1.0
    Preparing search index...

    Function once

    • Returns a wrapper that calls fn only on the first invocation. All subsequent calls return the cached result of the first call.

      Type Parameters

      • Args extends unknown[]
      • R

      Parameters

      • fn: (...args: Args) => R

        The function to wrap.

      Returns (...args: Args) => R

      const init = once(() => createConnection())
      init() // creates connection
      init() // returns cached connection