Skip to content

Commit e5de4b0

Browse files
authored
docs: document PlaygroundEvaluator lifecycle after killWorker (#645) (#706)
2 parents 0e58882 + 2fb9ab4 commit e5de4b0

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/commands/playground/executePlaygroundCode.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ export async function executePlaygroundCode(
169169

170170
token.onCancellationRequested(() => {
171171
cancelled = true;
172+
// killWorker() terminates the worker thread but the evaluator
173+
// instance stays in the pool. The next evaluate() call will
174+
// detect the dead worker and transparently spawn a new one.
172175
evaluator?.killWorker();
173176
});
174177

src/documentdb/playground/PlaygroundEvaluator.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@ import { type MainToWorkerMessage, type SerializableMongoClientOptions, type Wor
2828
*
2929
* The public API is unchanged from the in-process evaluator:
3030
* `evaluate(connection, code) → Promise<ExecutionResult>`
31+
*
32+
* ## Lifecycle
33+
*
34+
* The evaluator instance and the worker thread have **independent lifecycles**:
35+
*
36+
* ```
37+
* Evaluator instance Worker thread
38+
* ───────────────── ─────────────
39+
* new PlaygroundEvaluator()
40+
* └─ evaluate() ────────► spawn + connect
41+
* └─ evaluate() ────────► reuse (no re-auth)
42+
* └─ killWorker() ──────► terminate
43+
* └─ evaluate() ────────► re-spawn + re-connect
44+
* └─ shutdown() ────────► graceful close
45+
* ```
46+
*
47+
* After `killWorker()` (called on user cancellation), the evaluator instance
48+
* stays registered in the per-cluster evaluator pool (`evaluators` Map in
49+
* `executePlaygroundCode.ts`). The next `evaluate()` call detects that the
50+
* worker is dead and transparently spawns a new one. Session telemetry
51+
* (`_sessionId`, `_sessionEvalCount`) resets on each worker spawn, so a
52+
* killed-and-respawned worker behaves like a fresh evaluator session.
53+
*
54+
* The evaluator is only removed from the pool by `shutdownEvaluator()` (when
55+
* all playground documents for the cluster close) or by `disposeEvaluators()`
56+
* (on extension deactivation). `shutdownEvaluator()` calls `shutdown()`, while
57+
* `disposeEvaluators()` calls `dispose()`. Both paths gracefully close the
58+
* worker before removing the evaluator.
3159
*/
3260
export class PlaygroundEvaluator implements vscode.Disposable {
3361
private readonly _workerManager: WorkerSessionManager;

0 commit comments

Comments
 (0)