happy-rusty
    Preparing search index...

    Function FnOnceAsync

    • Creates a FnOnceAsync wrapper around an async function, making it callable only once.

      Type Parameters

      • A extends unknown[]

        Tuple type of the function arguments.

      • R

        The resolved type of the Promise returned by the async function.

      Parameters

      • fn: (...args: A) => R | PromiseLike<R>

        A function that returns PromiseLike<R> or R.

      Returns FnOnceAsync<A, R>

      A FnOnceAsync instance that wraps the function.

      const initialize = FnOnceAsync(async () => {
      console.log('Initializing...');
      await loadResources();
      return { ready: true };
      });

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