numbl 0.4.14 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,13 @@ export interface BootMessage {
16
16
  optimization: "0" | "1";
17
17
  maxIterations: number;
18
18
  displayResults: boolean;
19
+ /**
20
+ * Shared cancellation flag (Int32[0] != 0 ⇒ cancel the running code). The
21
+ * worker keeps this reference and passes it to every executeCode call, so
22
+ * the host can interrupt a runaway run cooperatively. Only present when the
23
+ * page is cross-origin isolated (SharedArrayBuffer available).
24
+ */
25
+ cancelSAB?: SharedArrayBuffer;
19
26
  }
20
27
  export type ToWorker = BootMessage | {
21
28
  type: "writeFile";
@@ -51,6 +58,12 @@ export interface ExecuteResult {
51
58
  plotInstructions: PlotInstruction[];
52
59
  /** Formatted error message when `ok` is false. */
53
60
  error?: string;
61
+ /**
62
+ * True when the run ended because it was interrupted via
63
+ * `NumblSession.interrupt()` (rather than finishing or erroring). The
64
+ * workspace is left at its pre-run state, so variables survive the abort.
65
+ */
66
+ aborted?: boolean;
54
67
  }
55
68
  export type FromWorker = {
56
69
  type: "progress";
@@ -57,6 +57,20 @@ export interface NumblSession {
57
57
  * the callback returns; rejects if it errors (the session stays usable).
58
58
  */
59
59
  dispatchHtmlEvent(compId: string, name: string, data: unknown): Promise<void>;
60
+ /**
61
+ * Cooperatively interrupt the currently running `execute` (or boot script):
62
+ * sets a shared cancel flag the worker polls at loop iterations and function
63
+ * calls, so it throws and the pending `execute` resolves with
64
+ * `aborted: true`. The worker and the persistent workspace survive — only
65
+ * the running command is abandoned. No-op when `canInterrupt` is false.
66
+ */
67
+ interrupt(): void;
68
+ /**
69
+ * Whether `interrupt()` can actually stop a run. True only when the page is
70
+ * cross-origin isolated (SharedArrayBuffer available). When false, a runaway
71
+ * run can only be stopped by disposing the session.
72
+ */
73
+ readonly canInterrupt: boolean;
60
74
  /** Terminate the worker. The session is unusable afterwards. */
61
75
  dispose(): void;
62
76
  }