Download packages/console/core/src/util/memo.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 392 Bytes
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/console/core/src/util/memo.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/console/core/src/util/memo.ts
-
curl -L -o memo.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/console/core/src/util/memo.ts
392 Bytes
| export function memo<T>(fn: () => T, cleanup?: (input: T) => Promise<void>) { | |
| let value: T | undefined | |
| let loaded = false | |
| const result = (): T => { | |
| if (loaded) return value as T | |
| loaded = true | |
| value = fn() | |
| return value as T | |
| } | |
| result.reset = async () => { | |
| if (cleanup && value) await cleanup(value) | |
| loaded = false | |
| value = undefined | |
| } | |
| return result | |
| } | |