diff options
author | veetaha <[email protected]> | 2020-05-31 03:13:08 +0100 |
---|---|---|
committer | veetaha <[email protected]> | 2020-05-31 03:21:45 +0100 |
commit | d605ec9c321392d9c7ee4b440c560e1e405d92e6 (patch) | |
tree | 58d16996d1d1a05733dcc85ae4efddc563b3d3b1 /editors/code/src/util.ts | |
parent | a419cedb1cc661349a022262c8b03993e063252f (diff) |
Change Runnable.bin -> Runnable.kind
As per matklad, we now pass the responsibility for finding the binary to the frontend.
Also, added caching for finding the binary path to reduce
the amount of filesystem interactions.
Diffstat (limited to 'editors/code/src/util.ts')
-rw-r--r-- | editors/code/src/util.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index 352ef9162..fe3fb71cd 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts | |||
@@ -99,3 +99,21 @@ export function isValidExecutable(path: string): boolean { | |||
99 | export function setContextValue(key: string, value: any): Thenable<void> { | 99 | export function setContextValue(key: string, value: any): Thenable<void> { |
100 | return vscode.commands.executeCommand('setContext', key, value); | 100 | return vscode.commands.executeCommand('setContext', key, value); |
101 | } | 101 | } |
102 | |||
103 | /** | ||
104 | * Returns a higher-order function that caches the results of invoking the | ||
105 | * underlying function. | ||
106 | */ | ||
107 | export function memoize<Ret, TThis, Param extends string>(func: (this: TThis, arg: Param) => Ret) { | ||
108 | const cache = new Map<string, Ret>(); | ||
109 | |||
110 | return function(this: TThis, arg: Param) { | ||
111 | const cached = cache.get(arg); | ||
112 | if (cached) return cached; | ||
113 | |||
114 | const result = func.call(this, arg); | ||
115 | cache.set(arg, result); | ||
116 | |||
117 | return result; | ||
118 | }; | ||
119 | } | ||