@tscircuit/runframe 0.0.499 → 0.0.501
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.
|
@@ -1093,7 +1093,7 @@ var RenderLogViewer = ({
|
|
|
1093
1093
|
};
|
|
1094
1094
|
|
|
1095
1095
|
// package.json
|
|
1096
|
-
var version = "0.0.
|
|
1096
|
+
var version = "0.0.500";
|
|
1097
1097
|
|
|
1098
1098
|
// lib/components/CircuitJsonPreview/CircuitJsonPreview.tsx
|
|
1099
1099
|
import { jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
|
package/dist/preview.js
CHANGED
package/dist/runner.js
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
useOrderDialog,
|
|
28
28
|
useOrderDialogCli,
|
|
29
29
|
useRunFrameStore
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-QNALISUL.js";
|
|
31
31
|
|
|
32
32
|
// lib/components/RunFrame/RunFrame.tsx
|
|
33
33
|
import { createCircuitWebWorker } from "@tscircuit/eval/worker";
|
|
@@ -107,9 +107,12 @@ import { useCallback, useRef } from "react";
|
|
|
107
107
|
function useMutex() {
|
|
108
108
|
const lockRef = useRef(Promise.resolve());
|
|
109
109
|
const isLockedRef = useRef(false);
|
|
110
|
+
const currentExecutionRef = useRef(null);
|
|
110
111
|
const runWithMutex = useCallback(
|
|
111
112
|
async (fn) => {
|
|
112
113
|
await lockRef.current;
|
|
114
|
+
const executionContext = { cancelled: false };
|
|
115
|
+
currentExecutionRef.current = executionContext;
|
|
113
116
|
let releaseLock;
|
|
114
117
|
const newLock = new Promise((resolve) => {
|
|
115
118
|
releaseLock = resolve;
|
|
@@ -118,15 +121,27 @@ function useMutex() {
|
|
|
118
121
|
lockRef.current = newLock;
|
|
119
122
|
isLockedRef.current = true;
|
|
120
123
|
return await fn();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (!executionContext.cancelled) {
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
121
128
|
} finally {
|
|
122
129
|
isLockedRef.current = false;
|
|
130
|
+
currentExecutionRef.current = null;
|
|
123
131
|
releaseLock();
|
|
124
132
|
}
|
|
125
133
|
},
|
|
126
134
|
[]
|
|
127
135
|
);
|
|
136
|
+
const cancel = useCallback(() => {
|
|
137
|
+
if (currentExecutionRef.current) {
|
|
138
|
+
currentExecutionRef.current.cancelled = true;
|
|
139
|
+
}
|
|
140
|
+
lockRef.current = Promise.resolve();
|
|
141
|
+
isLockedRef.current = false;
|
|
142
|
+
}, []);
|
|
128
143
|
const isLocked = useCallback(() => isLockedRef.current, []);
|
|
129
|
-
return { runWithMutex, isLocked };
|
|
144
|
+
return { runWithMutex, isLocked, cancel };
|
|
130
145
|
}
|
|
131
146
|
|
|
132
147
|
// lib/components/RunFrame/RunFrame.tsx
|
|
@@ -139,6 +154,7 @@ var RunFrame = (props) => {
|
|
|
139
154
|
s.setCircuitJson
|
|
140
155
|
]);
|
|
141
156
|
const [error, setError] = useState(null);
|
|
157
|
+
const cancelExecutionRef = useRef2(null);
|
|
142
158
|
const [autoroutingGraphics, setAutoroutingGraphics] = useState(null);
|
|
143
159
|
const [runCountTrigger, incRunCountTrigger] = useReducer(
|
|
144
160
|
(acc, s) => acc + 1,
|
|
@@ -203,7 +219,12 @@ var RunFrame = (props) => {
|
|
|
203
219
|
const runWorker = async () => {
|
|
204
220
|
debug("running render worker");
|
|
205
221
|
setError(null);
|
|
222
|
+
setRenderLog(null);
|
|
206
223
|
const renderLog2 = { progress: 0 };
|
|
224
|
+
let cancelled = false;
|
|
225
|
+
cancelExecutionRef.current = () => {
|
|
226
|
+
cancelled = true;
|
|
227
|
+
};
|
|
207
228
|
let evalVersion = props.evalVersion ?? "latest";
|
|
208
229
|
if (!globalThis.runFrameWorker && props.forceLatestEvalVersion) {
|
|
209
230
|
try {
|
|
@@ -246,7 +267,9 @@ var RunFrame = (props) => {
|
|
|
246
267
|
const estProgressLinear = orderedRenderPhases2.indexOf(event.phase) / numRenderPhases * 0.75 + renderLog2.eventsProcessed / 1e3 * 0.25;
|
|
247
268
|
const estProgress = 1 - Math.exp(-estProgressLinear * 3);
|
|
248
269
|
renderLog2.progress = estProgress;
|
|
249
|
-
|
|
270
|
+
if (!cancelled) {
|
|
271
|
+
setRenderLog({ ...renderLog2 });
|
|
272
|
+
}
|
|
250
273
|
});
|
|
251
274
|
if (activeTab === "render_log") {
|
|
252
275
|
worker.on("renderable:renderLifecycle:anyEvent", (event) => {
|
|
@@ -259,7 +282,9 @@ var RunFrame = (props) => {
|
|
|
259
282
|
);
|
|
260
283
|
lastRenderLogSet = Date.now();
|
|
261
284
|
}
|
|
262
|
-
|
|
285
|
+
if (!cancelled) {
|
|
286
|
+
setRenderLog({ ...renderLog2 });
|
|
287
|
+
}
|
|
263
288
|
});
|
|
264
289
|
}
|
|
265
290
|
worker.on("autorouting:progress", (event) => {
|
|
@@ -309,8 +334,11 @@ var RunFrame = (props) => {
|
|
|
309
334
|
);
|
|
310
335
|
}
|
|
311
336
|
renderLog2.progress = 1;
|
|
312
|
-
|
|
337
|
+
if (!cancelled) {
|
|
338
|
+
setRenderLog({ ...renderLog2 });
|
|
339
|
+
}
|
|
313
340
|
setIsRunning(false);
|
|
341
|
+
cancelExecutionRef.current = null;
|
|
314
342
|
};
|
|
315
343
|
runMutex.runWithMutex(runWorker);
|
|
316
344
|
}, [props.fsMap, props.entrypoint, runCountTrigger, props.evalVersion]);
|
|
@@ -394,6 +422,13 @@ var RunFrame = (props) => {
|
|
|
394
422
|
onClick: (e) => {
|
|
395
423
|
e.stopPropagation();
|
|
396
424
|
setIsRunning(false);
|
|
425
|
+
setRenderLog(null);
|
|
426
|
+
setError(null);
|
|
427
|
+
if (cancelExecutionRef.current) {
|
|
428
|
+
cancelExecutionRef.current();
|
|
429
|
+
cancelExecutionRef.current = null;
|
|
430
|
+
}
|
|
431
|
+
runMutex.cancel();
|
|
397
432
|
if (globalThis.runFrameWorker) {
|
|
398
433
|
globalThis.runFrameWorker.kill();
|
|
399
434
|
globalThis.runFrameWorker = null;
|