closeout
API reference

closeout/onetime

Every export of closeout/onetime, with its signature and doc comment: onetime, plus 2 types.

closeout/onetime — the drop-in path for onetime 8 (graded-override-targets R3).

import onetime from 'closeout/onetime';
import type { Options, OnetimeFunction } from 'closeout/onetime';

Constants

default

The default export, declared as onetime.

Ensure a function is called once; later calls return the first result.

const onetime: typeof onceUntilReturned & {
    callCount: typeof callCount;
};

Interfaces

Options

Options onetime takes.

interface Options {
    /** Throw when called more than once, instead of returning the first result. */
    readonly throw?: boolean;
}

Types

OnetimeFunction

A function wrapped by onetime: the same signature, called through the wrapper.

type OnetimeFunction<ArgumentsType extends unknown[], ReturnType> = (...arguments_: ArgumentsType) => ReturnType;

On this page