| 771 | } |
| 772 | |
| 773 | async close(): Promise<void> { |
| 774 | // Close every cached handle in parallel. Drop caches before |
| 775 | // awaiting so a subsequent ready() / exec sees an empty slate |
| 776 | // and rebuilds against fresh handles. |
| 777 | this.#connectionGeneration += 1; |
| 778 | const handles = [...this.#handles.values()]; |
| 779 | const moduleHandles = [...this.#moduleHandles.values()]; |
| 780 | this.#handles.clear(); |
| 781 | this.#shells.clear(); |
| 782 | this.#connecting.clear(); |
| 783 | this.#moduleHandles.clear(); |
| 784 | this.#connectingModuleHandles.clear(); |
| 785 | this.#readyPromise = undefined; |
| 786 | await Promise.all( |
| 787 | [...handles, ...moduleHandles].map(async (h) => { |
| 788 | try { |
| 789 | await h.close(); |
| 790 | } catch { |
| 791 | // close() is best-effort; a transport that's already |
| 792 | // gone shouldn't take the workspace down with it. |
| 793 | } |
| 794 | }), |
| 795 | ); |
| 796 | } |
| 797 | |
| 798 | #moduleHandleFor(id: string): Promise<WorkspaceModuleBackendHandle> { |
| 799 | const cached = this.#moduleHandles.get(id); |