Type Parameters

  • K

    The key type.

  • V

    The value type.

Constructors

  • Type Parameters

    • K

      The key type.

    • V

      The value type.

    Parameters

    • Optional entries: readonly (readonly [K, V])[]

      Initial entries for the map.

    Returns ConcurrentMap<K, V>

Accessors

  • get size(): number
  • Returns number

    The number of entries currently in the map. This is a snapshot; the results of any pending actions will not be visible yet.

Methods

  • Returns an iterator over the entries in the map.

    Returns IterableIterator<[K, V]>

    A new iterator over the entries in the map. This is a snapshot; the results of any pending actions will not be visible yet.

  • Deletes all entries. If there are no pending actions for a key its entry will be deleted immediately. Otherwise its entry will only be deleted until all pending actions have finished.

    Returns Promise<void>

    A promise that will be resolved once every entry has been deleted.

    The promise will not be resolved until all current entries have been removed once; at that time new entries may have been added though. The promise will never be rejected.

  • Computes the value for a key. The new value will be the return value of calling the given function. If the given function throws an error, the error is propagated through the returned promise and no value is set or removed.

    Parameters

    • key: K

      The key to compute the value for.

    • fn: ((k, v?) => V | PromiseLike<V>)

      The function to compute the value. Its input will be the key and previous value, or undefined if there was no entry yet.

        • (k, v?): V | PromiseLike<V>
        • Parameters

          • k: K
          • Optional v: V

          Returns V | PromiseLike<V>

    Returns Promise<V>

    A promise that will be resolved with the new value for the key.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will be rejected if the given function throws an error.

  • Computes the value for a key. The new value will be the return value of calling the given function. However, if the given function returns undefined, any existing entry is removed instead. If the given function throws an error, the error is propagated through the returned promise and no value is set or removed.

    Parameters

    • key: K

      The key to compute the value for.

    • fn: ((k, v?) => undefined | V | PromiseLike<undefined | V>)

      The function to compute the value. Its input will be the key and previous value, or undefined if there was no entry yet.

        • (k, v?): undefined | V | PromiseLike<undefined | V>
        • Parameters

          • k: K
          • Optional v: V

          Returns undefined | V | PromiseLike<undefined | V>

    Returns Promise<undefined | V>

    A promise that will be resolved with the new value for the key, or undefined if the given function returns undefined.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will be rejected if the given function throws an error.

  • Computes the value for a key only if there is no entry for the key yet. The new value will be the return value of calling the given function. If the given function throws an error, the error is propagated through the returned promise and no value is set.

    Parameters

    • key: K

      The key to compute the value for.

    • fn: ((k) => V | PromiseLike<V>)

      The function to compute the value. Its input will be the key.

        • (k): V | PromiseLike<V>
        • Parameters

          • k: K

          Returns V | PromiseLike<V>

    Returns Promise<V>

    A promise that will be resolved with the new value for the key.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will be rejected if the given function throws an error.

  • Computes the value for a key only if there is no entry for the key yet. The new value will be the return value of calling the given function. However, if the given function returns undefined, no value is set. If the given function throws an error, the error is propagated through the returned promise and no value is set.

    Parameters

    • key: K

      The key to compute the value for.

    • fn: ((k) => undefined | V | PromiseLike<undefined | V>)

      The function to compute the value. Its input will be the key.

        • (k): undefined | V | PromiseLike<undefined | V>
        • Parameters

          • k: K

          Returns undefined | V | PromiseLike<undefined | V>

    Returns Promise<undefined | V>

    A promise that will be resolved with the new value for the key, or undefined if the given function returns undefined.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will be rejected if the given function throws an error.

  • Computes the value for a key only if there is entry for the key already. The new value will be the return value of calling the given function. However, if the given function returns undefined, the entry is removed instead. If the given function throws an error, the error is propagated through the returned promise and no value is set or removed.

    Parameters

    • key: K

      The key to compute the value for.

    • fn: ((k, v) => undefined | V | PromiseLike<undefined | V>)

      The function to compute the value. Its input will be the key and previous value.

        • (k, v): undefined | V | PromiseLike<undefined | V>
        • Parameters

          • k: K
          • v: V

          Returns undefined | V | PromiseLike<undefined | V>

    Returns Promise<undefined | V>

    A promise that will be resolved with the new value for the key, or undefined if there was no entry for the given key or if the given function returns undefined.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will be rejected if the given function throws an error.

  • Deletes the entry for a key.

    Parameters

    • key: K

      The key to delete the entry for.

    Returns Promise<undefined | V>

    A promise that will be resolved with the previous value for the key, or undefined if there was no entry for the key.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will never be rejected.

  • Deletes the entry for a key only if it's currently mapped to a given value.

    Parameters

    • key: K

      The key to delete the entry for.

    • value: NonNullable<V>

      The value for the key.

    Returns Promise<boolean>

    A promise that will be resolved with true if the entry was deleted, or false otherwise.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will never be rejected.

  • Returns an iterator over the entries in the map.

    Returns IterableIterator<[K, V]>

    A new iterator over the entries in the map. This is a snapshot; the results of any pending actions will not be visible yet.

  • Executes a given callback on each entry. This is a snapshot; the results of any pending actions will not be visible yet.

    Parameters

    • callback: ((v, k, map) => void)

      The function to call for each entry. Its arguments will be the value, key and this map.

        • (v, k, map): void
        • Parameters

          Returns void

    Returns void

  • Returns the value for a key, if available.

    Parameters

    • key: K

      The key to return the value for.

    Returns undefined | V

    The value for the key, or undefined if there is no entry for the given key. This is a snapshot; the results of any pending actions will not be visible yet.

  • Returns the value for a key, if available.

    Parameters

    • key: K

      The key to return the value for.

    Returns Promise<undefined | V>

    A promise that will be resolved with the value for the key, or undefined if there is no entry for the key.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will never be rejected.

  • Checks whether there is an entry for a key.

    Parameters

    • key: K

      The key to check.

    Returns boolean

    true if there is an entry for the key, or false otherwise. This is a snapshot; the results of any pending actions will not be visible yet.

  • Returns an iterator over the keys in the map.

    Returns IterableIterator<K>

    A new iterator over the keys in the map. This is a snapshot; the results of any pending actions will not be visible yet.

  • Sets the value for a key, merging it with any existing value if necessary. If there was no entry yet for the key, its value will be set to the given value. Otherwise, the new value will be the return value of calling the given function. If the given function throws an error, the error is propagated through the returned promise and no value is set or removed.

    Parameters

    • key: K

      The key to compute the value for.

    • value: V
    • fn: ((oldValue, newValue) => V | PromiseLike<V>)

      The function to compute the value. Its input will be the previous value and the given value.

        • (oldValue, newValue): V | PromiseLike<V>
        • Parameters

          • oldValue: V
          • newValue: V

          Returns V | PromiseLike<V>

    Returns Promise<V>

    A promise that will be resolved with the new value for the key.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will be rejected if the given function throws an error.

  • Sets the value for a key, merging it with any existing value if necessary. If there was no entry yet for the key, its value will be set to the given value. Otherwise, the new value will be the return value of calling the given function. However, if the given function returns undefined, the entry is removed instead. If the given function throws an error, the error is propagated through the returned promise and no value is set or removed.

    Parameters

    • key: K

      The key to compute the value for.

    • value: V
    • fn: ((oldValue, newValue) => undefined | V | PromiseLike<undefined | V>)

      The function to compute the value. Its input will be the previous value and the given value.

        • (oldValue, newValue): undefined | V | PromiseLike<undefined | V>
        • Parameters

          • oldValue: V
          • newValue: V

          Returns undefined | V | PromiseLike<undefined | V>

    Returns Promise<undefined | V>

    A promise that will be resolved with the new value for the key, or undefined if the given function returns undefined.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will be rejected if the given function throws an error.

  • Sets the value for a key only if it is currently mapped to a given value. This is similar to setIfPresent, except this method will only replace the given value.

    Parameters

    • key: K

      The key to set the value for.

    • oldValue: NonNullable<V>

      The value to replace.

    • newValue: NonNullable<V>

      The new value to set.

    Returns Promise<boolean>

    A promise that will be resolved with true if the key was previously mapped to the given value, or false otherwise.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will never be rejected.

  • Sets the value for a key.

    Parameters

    • key: K

      The key to set the value for.

    • value: NonNullable<V>

      The value to set.

    Returns Promise<undefined | V>

    A promise that will be resolved with the previous value for the key, or undefined if there was no entry for the key.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will never be rejected.

  • Sets the value for a key only if there is no entry for the key yet.

    Parameters

    • key: K

      The key to set the value for.

    • value: NonNullable<V>

      The value to set.

    Returns Promise<undefined | V>

    A promise that will be resolved with the previous value for the key, or undefined if there was no entry for the key.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will never be rejected.

  • Sets the value for a key only if there is an entry for the key already. This is similar to replace, except this method will replace any existing value.

    Parameters

    • key: K

      The key to set the value for.

    • value: NonNullable<V>

      The value to set.

    Returns Promise<undefined | V>

    A promise that will be resolved with the previous value for the key, or undefined if there was no entry for the key.

    If there are any pending actions for the key the returned promise will not be resolved until they have all finished. The promise will never be rejected.

  • Returns an iterator over the values in the map.

    Returns IterableIterator<V>

    A new iterator over the values in the map. This is a snapshot; the results of any pending actions will not be visible yet.