Class PerishableList<T>

A list class where items are removed after their given expiration time.

const list = new PerishableList<string>();

list.add("Hello, World!", 1000);

console.log(list.items); // ["Hello, World!"];

await sleep(1000);

console.log(list.items); // [];

Type Parameters

  • T

Constructors

Accessors

Methods

Constructors

Accessors

Methods

  • Adds an item to the list with an expiresIn time. The item will be removed from the list if the expiresIn time has passed.

    list.add("Hello, World!", 1000);
    

    Parameters

    • item: T
    • expiresIn: number

    Returns number

    id of the item

  • Removes all items from the list.

    list.clear();
    

    Returns void

  • Removes an item from the list with the key returned from the add method.

    const key = list.add("Hello, World!", 1000);

    list.remove(key);

    Parameters

    • index: number

    Returns void