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

Commit9bd5bcd

Browse files
committed
interruptible sleep
1 parent67fd898 commit9bd5bcd

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

‎frontend/src/RunCode.js‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,19 @@ if (typeof SharedArrayBuffer != "undefined") {
4242
exportconstterminalRef=React.createRef();
4343

4444
letawaitingInput=false;
45+
letsleeping=false;
4546
letpendingOutput=[];
4647

4748
localforage.config({name:"birdseye",storeName:"birdseye"});
4849

49-
functioninputCallback(messageId){
50-
awaitingInput=messageId;
51-
bookSetState("processing",false);
52-
terminalRef.current.focusTerminal();
50+
functioninputCallback(messageId,data){
51+
if(data.sleeping){
52+
sleeping=messageId;
53+
}else{
54+
awaitingInput=messageId;
55+
bookSetState("processing",false);
56+
terminalRef.current.focusTerminal();
57+
}
5358
}
5459

5560
exportletinterrupt=()=>{
@@ -83,6 +88,7 @@ export const runCode = async ({code, source}) => {
8388
}
8489

8590
awaitingInput=false;
91+
sleeping=false;
8692
pendingOutput=[];
8793

8894
bookSetState("processing",true);
@@ -108,9 +114,10 @@ export const runCode = async ({code, source}) => {
108114
letinterruptResolver;
109115
constinterruptPromise=newPromise(r=>interruptResolver=r);
110116
interrupt=async()=>{
111-
if(awaitingInput){
112-
constmessageId=awaitingInput;
117+
if(awaitingInput||sleeping){
118+
constmessageId=awaitingInput||sleeping;
113119
awaitingInput=false;
120+
sleeping=false;
114121
awaitwriteMessage(channel,{interrupted:true},messageId);
115122
}else{
116123
doInterrupt();
@@ -165,6 +172,7 @@ export const runCode = async ({code, source}) => {
165172
]);
166173

167174
awaitingInput=false;
175+
sleeping=false;
168176

169177
const{error}=data;
170178

‎frontend/src/Worker.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,17 @@ async function runCode(entry, channel, interruptBuffer, outputCallback, inputCal
104104
};
105105

106106
functionsleepCallback(data){
107-
syncSleep(toObject(data).seconds*1000,channel);
107+
consttimeout=toObject(data).seconds*1000;
108+
if(!(timeout>0&&channel)){
109+
return;
110+
}
111+
constmessageId=uuidv4();
112+
try{
113+
inputCallback(messageId,{sleeping:true});
114+
readMessage(channel,messageId,{timeout});
115+
}catch(e){
116+
console.error(e);
117+
}
108118
}
109119

110120
constresult=check_entry(entry,fullInputCallback,fullOutputCallback,sleepCallback);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp