happy-rusty
    Preparing search index...

    Function FnOnce

    • Creates a FnOnce wrapper around a function, making it callable only once.

      Type Parameters

      • A extends unknown[]

        Tuple type of the function arguments.

      • R

        Return type of the function.

      Parameters

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

        The function to wrap.

      Returns FnOnce<A, R>

      A FnOnce instance that wraps the function.

      const initialize = FnOnce(() => {
      console.log('Initializing...');
      return { ready: true };
      });

      const result = initialize.call(); // Logs 'Initializing...', returns { ready: true }
      // initialize.call(); // Throws Error: FnOnce has already been consumed