Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit258ab1d

Browse files
committed
interrupt with terminate
1 parent8325407 commit258ab1d

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

‎frontend/src/RunCode.js‎

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ import React from "react";
2020
import*asSentryfrom"@sentry/react";
2121
import{makeAtomicsChannel,makeServiceWorkerChannel}from"sync-message";
2222

23-
constworkerWrapper=Comlink.wrap(newWorker());
23+
letworker,workerWrapper;
24+
25+
functioninitWorker(){
26+
worker=newWorker();
27+
workerWrapper=Comlink.wrap(worker);
28+
}
29+
30+
initWorker();
2431

2532
constchannelPromise=(async()=>{
2633
if(typeofSharedArrayBuffer!=="undefined"){
@@ -93,14 +100,30 @@ export const runCode = async ({code, source}) => {
93100
expected_output:questionWizard.expectedOutput,
94101
};
95102

96-
interrupt();
97103
letinterrupted=false;
104+
letinterruptResolver;
105+
constinterruptPromise=newPromise(r=>interruptResolver=r);
106+
interrupt=()=>{
107+
doInterrupt();
108+
interrupted=true;
109+
}
98110

99-
if(typeofSharedArrayBuffer!=="undefined"){
111+
letdoInterrupt;
112+
if(typeofSharedArrayBuffer==="undefined"){
113+
doInterrupt=()=>{
114+
worker.terminate();
115+
initWorker();
116+
interruptResolver({
117+
interrupted:true,
118+
error:null,
119+
passed:false,
120+
messages:[],
121+
});
122+
}
123+
}else{
100124
interruptBuffer=newInt32Array(newSharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT*1));
101-
interrupt=()=>{
125+
doInterrupt=()=>{
102126
interruptBuffer[0]=2;
103-
interrupted=true;
104127
}
105128
}
106129

@@ -120,13 +143,16 @@ export const runCode = async ({code, source}) => {
120143
}
121144
}
122145

123-
constdata=awaitworkerWrapper.runCode(
124-
entry,
125-
(awaitchannelPromise).channel,
126-
interruptBuffer,
127-
Comlink.proxy(outputCallback),
128-
Comlink.proxy(inputCallback),
129-
);
146+
constdata=awaitPromise.race([
147+
interruptPromise,
148+
workerWrapper.runCode(
149+
entry,
150+
(awaitchannelPromise).channel,
151+
interruptBuffer,
152+
Comlink.proxy(outputCallback),
153+
Comlink.proxy(inputCallback),
154+
),
155+
]);
130156

131157
awaitingInput=false;
132158

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp