UNPKG

1.64 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at
5 * http://polymer.github.io/LICENSE.txt
6 * The complete set of authors may be found at
7 * http://polymer.github.io/AUTHORS.txt
8 * The complete set of contributors may be found at
9 * http://polymer.github.io/CONTRIBUTORS.txt
10 * Code distributed by Google as part of the polymer project is also
11 * subject to an additional IP rights grant found at
12 * http://polymer.github.io/PATENTS.txt
13 */
14import { MinimalCancelToken } from './cancel-token';
15/**
16 * A map from keys to promises of values. Used for caching asynchronous work.
17 */
18export declare class AsyncWorkCache<K, V> {
19 private _keyToResultMap;
20 constructor(from?: AsyncWorkCache<K, V>);
21 /**
22 * If work has already begun to compute the given key, return a promise for
23 * the result of that work.
24 *
25 * If not, compute it with the given function.
26 *
27 * This method ensures that, in the absence of cancellations, we will only try
28 * to compute the value for `key` once, no matter how often or with what
29 * timing getOrCompute is called, even recursively.
30 *
31 * This API is safe for multiple, independently cancellable callers. So long
32 * as the given cancelToken is not cancelled, this function will not reject
33 * with a Cancel exception.
34 */
35 getOrCompute(key: K, compute: () => Promise<V>, cancelToken?: MinimalCancelToken): Promise<V>;
36 private _getOrCompute;
37 delete(key: K): void;
38 clear(): void;
39 set(key: K, value: V): void;
40 has(key: K): boolean;
41}