Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TimedSingleton and VaradicTimedSingleton classes #94

Closed
samchon opened this issue Mar 12, 2022 · 0 comments
Closed

Implement TimedSingleton and VaradicTimedSingleton classes #94

samchon opened this issue Mar 12, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@samchon
Copy link
Owner

samchon commented Mar 12, 2022

Implement new type of (variadic) singleton classes who re-generates internal value repeatedly following an interval value.

It would be very useful for client side programs who need to refresh activation token for a promised time repeatedly.

/**
 * Timed singleton generator.
 * 
 * The `TimedSingleton` is a type of {@link Singleton} class who re-constructs the singleton 
 * value repeatedly whenever specific time has been elapsed after the last lazy construction.
 * 
 * @template T Type of the value to be lazy-constructed
 * @author Jeongho Nam - https://github.com/samchon
 */
export class TimedSingleton<T, Args extends any[] = []>
{
    /**
     * Initializer Constructor.
     * 
     * @param interval Specific interval time, to determine whether re-generation of the singleton value is required or not, as milliseconds
     * @param closure Lazy constructor function returning the target value
     */
    public constructor
        (
            interval: number;
            closure: (...args: Args) => T
        );

    public get(...args: Args): T;
}

/**
 * Variadic timed singleton generator.
 * 
 * The `VariadicTimedSingleton` is a type of {@link VariadicSingleton} class who re-constructs
 * the singleton value repeatedly whenever specific time has been elapsed after the last lazy
 * construction.
 * 
 * @template T Type of the value to be lazy-constructed
 * @template Args Type of parameters of the lazy constructor function
 * @author Jeongho Nam - https://github.com/samchon
 */
export class VariadicTimedSingleton<T, Args extends any[]>
{
    /**
     * Initializer Constructor.
     * 
     * @param interval Specific interval time, to determine whether re-generation of the singleton value is required or not, as milliseconds
     * @param closure Lazy constructor function returning the target value
     * @param hasher Hash function for the *lazy constructor* function arguments
     * @param pred Predicator function for the *lazy constructor* function arguments
     */
    public constructor
        (
            interval: number,
            closure: (...args: Args) => T,
            hasher: (args: Args) => number = args => hash(...args),
            pred: (x: Args, y: Args) => boolean = equal
        );

    public get(...args: Args): T;
}
@samchon samchon added the enhancement New feature or request label Mar 12, 2022
@samchon samchon self-assigned this Mar 12, 2022
@samchon samchon changed the title Implement TimedSingleton and VaradicTimedSingleton Implement RepeatedSingleton and VaradicRepeatedSingleton Mar 12, 2022
@samchon samchon changed the title Implement RepeatedSingleton and VaradicRepeatedSingleton Implement TimedSingleton and VaradicTimedSingleton classes Mar 12, 2022
samchon added a commit that referenced this issue Mar 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant