| 11 | }; |
| 12 | |
| 13 | export function attachLanguageModelCleanup( |
| 14 | model: LanguageModel, |
| 15 | cleanup: LanguageModelCleanup |
| 16 | ): void { |
| 17 | assert(typeof cleanup === "function", "language model cleanup must be a function"); |
| 18 | assert( |
| 19 | !hasLanguageModelCleanup(model), |
| 20 | "language model already has cleanup attached; call moveLanguageModelCleanup instead" |
| 21 | ); |
| 22 | const modelWithCleanup = model as LanguageModelWithCleanup; |
| 23 | modelWithCleanup[languageModelCleanupSymbol] = cleanup; |
| 24 | } |
| 25 | |
| 26 | // Single-shot pop: read the attached cleanup (if any) and clear the slot in one |
| 27 | // step so move/run callers can't accidentally leave a stale cleanup behind that |