@sensimods/utility-lab
    Preparing search index...

    Function once

    • Ensures a function can only be called once. Subsequent calls will return the result of the first execution.

      Type Parameters

      • T extends (...args: any[]) => any

      Parameters

      • func: T

        The function to execute only once.

      Returns (...args: Parameters<T>) => ReturnType<T>

      A new function that expects the exact same parameters as the original.

      const initialize = once(() => {
      console.log("Setup complete!");
      return { status: "ready" };
      });

      initialize(); // Logs "Setup complete!"
      initialize(); // Does nothing, just returns { status: "ready" }