@vgerbot/async
    Preparing search index...

    Function once

    • Creates a function that executes only once. Subsequent calls return the cached result. Similar to memoize but doesn't consider arguments - always returns the same result.

      Type Parameters

      • T

        The return type of the function.

      Parameters

      Returns () => CancellableHandle<T>

      A function that returns a cancellable handle, executing only on first call.

      let count = 0;
      const initialize = once(async () => {
      count++;
      return "initialized";
      });

      await initialize(); // count = 1, returns "initialized"
      await initialize(); // count = 1, returns "initialized" (cached)