Skip to content

Commit

Permalink
clarify abort ref thing
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Feb 5, 2025
1 parent 31008d3 commit c75e18a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/web/app/src/lib/preflight/graphiql-plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function usePreflight(args: {
const [state, setState] = useState<PreflightWorkerState>(PreflightWorkerState.ready);
const [logs, setLogs] = useState<LogRecord[]>([]);

const currentExecution = useRef<null | Function>(null);
const abortExecutionRef = useRef<null | (() => void)>(null);

async function execute(
script = target?.preflightScript?.sourceCode ?? '',
Expand Down Expand Up @@ -366,15 +366,15 @@ export function usePreflight(args: {
}

window.addEventListener('message', eventHandler);
currentExecution.current = () => {
abortExecutionRef.current = () => {
contentWindow.postMessage({
type: IFrameEvents.Incoming.Event.abort,
id,
} satisfies IFrameEvents.Incoming.EventData);

closedOpenedPrompts();

currentExecution.current = null;
abortExecutionRef.current = null;
};

await isFinishedD.promise;
Expand Down Expand Up @@ -407,13 +407,13 @@ export function usePreflight(args: {
}

function abortExecution() {
currentExecution.current?.();
abortExecutionRef.current?.();
}

// terminate worker when leaving laboratory
useEffect(
() => () => {
currentExecution.current?.();
abortExecutionRef.current?.();
},
[],
);
Expand Down

0 comments on commit c75e18a

Please sign in to comment.