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

Commit32f7a1b

Browse files
committed
better interrupting of input
1 parent1f13ebe commit32f7a1b

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

‎frontend/src/RunCode.js‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const runCode = async ({code, source}) => {
7373
if(awaitingInput){
7474
constmessageId=awaitingInput;
7575
awaitingInput=false;
76-
(awaitchannelPromise).writeInput(code,messageId);
76+
(awaitchannelPromise).writeInput(JSON.stringify({text:code}),messageId);
7777
bookSetState("processing",true);
7878
return;
7979
}
@@ -112,8 +112,14 @@ export const runCode = async ({code, source}) => {
112112
letinterrupted=false;
113113
letinterruptResolver;
114114
constinterruptPromise=newPromise(r=>interruptResolver=r);
115-
interrupt=()=>{
116-
doInterrupt();
115+
interrupt=async()=>{
116+
if(awaitingInput){
117+
constmessageId=awaitingInput;
118+
awaitingInput=false;
119+
(awaitchannelPromise).writeInput(JSON.stringify({interrupted:true}),messageId);
120+
}else{
121+
doInterrupt();
122+
}
117123
interrupted=true;
118124
}
119125

‎frontend/src/Worker.js‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,9 @@ async function runCode(entry, channel, interruptBuffer, outputCallback, inputCal
6969
constfullInputCallback=(data)=>{
7070
constmessageId=Math.random()+" "+newDate();
7171
inputCallback(messageId,toObject(data));
72-
functioncheckInterrupt(){
73-
returninterruptBuffer?.[0]===2;
74-
}
75-
constresult=readChannel(
76-
channel,
77-
messageId,
78-
{checkInterrupt}
79-
);
80-
if(result===null){
81-
returnresult;
72+
constresult=JSON.parse(readChannel(channel,messageId)).text;
73+
if(result==null){
74+
returnnull;
8275
}
8376
returnresult+"\n";
8477
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp