mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-15 23:05:41 +00:00
use async version
This commit is contained in:
parent
c943057038
commit
d13f6ba750
3 changed files with 28 additions and 20 deletions
|
@ -126,16 +126,16 @@ export function setContextValue(key: string, value: any): Thenable<void> {
|
|||
|
||||
/**
|
||||
* Returns a higher-order function that caches the results of invoking the
|
||||
* underlying function.
|
||||
* underlying async function.
|
||||
*/
|
||||
export function memoize<Ret, TThis, Param extends string>(func: (this: TThis, arg: Param) => Ret) {
|
||||
export function memoizeAsync<Ret, TThis, Param extends string>(func: (this: TThis, arg: Param) => Promise<Ret>) {
|
||||
const cache = new Map<string, Ret>();
|
||||
|
||||
return function(this: TThis, arg: Param) {
|
||||
return async function (this: TThis, arg: Param) {
|
||||
const cached = cache.get(arg);
|
||||
if (cached) return cached;
|
||||
|
||||
const result = func.call(this, arg);
|
||||
const result = await func.call(this, arg);
|
||||
cache.set(arg, result);
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue