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

Commitc8e6da1

Browse files
committed
sync-message 0.0.7
1 parent51eea8e commitc8e6da1

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed

‎frontend/package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎frontend/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"redux-logger":"^3.0.6",
3737
"redux-thunk":"^2.3.0",
3838
"sass":"^1.32.8",
39-
"sync-message":"0.0.3"
39+
"sync-message":"0.0.7"
4040
},
4141
"scripts": {
4242
"start":"craco start",

‎frontend/src/RunCode.js‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import localforage from "localforage";
1818
import{animateScroll}from"react-scroll";
1919
importReactfrom"react";
2020
import*asSentryfrom"@sentry/react";
21-
import{makeAtomicsChannel,makeServiceWorkerChannel}from"sync-message";
21+
import{makeChannel,writeMessage}from"sync-message";
2222

2323
letworker,workerWrapper;
2424

@@ -29,19 +29,10 @@ function initWorker() {
2929

3030
initWorker();
3131

32-
constchannelPromise=(async()=>{
33-
if(typeofSharedArrayBuffer!=="undefined"){
34-
returnmakeAtomicsChannel();
35-
}else{
36-
awaitnavigator.serviceWorker.register("./service-worker.js");
37-
constresult=awaitmakeServiceWorkerChannel({timeout:1000});
38-
if(!result){
39-
// TODO what if this doesn't work?
40-
window.location.reload();
41-
}
42-
returnresult;
43-
}
44-
})();
32+
constchannel=makeChannel({serviceWorker:{scope:"/course/"}});
33+
if(channel?.type==="serviceWorker"){
34+
navigator.serviceWorker.register("/course/service-worker.js",{scope:"/course/"});
35+
}
4536

4637
letinterruptBuffer=null;
4738
if(typeofSharedArrayBuffer!="undefined"){
@@ -73,7 +64,7 @@ export const runCode = async ({code, source}) => {
7364
if(awaitingInput){
7465
constmessageId=awaitingInput;
7566
awaitingInput=false;
76-
(awaitchannelPromise).writeInput({text:code},messageId);
67+
awaitwriteMessage(channel,{text:code},messageId);
7768
bookSetState("processing",true);
7869
return;
7970
}
@@ -116,7 +107,7 @@ export const runCode = async ({code, source}) => {
116107
if(awaitingInput){
117108
constmessageId=awaitingInput;
118109
awaitingInput=false;
119-
(awaitchannelPromise).writeInput({interrupted:true},messageId);
110+
awaitwriteMessage(channel,{interrupted:true},messageId);
120111
}else{
121112
doInterrupt();
122113
}
@@ -162,7 +153,7 @@ export const runCode = async ({code, source}) => {
162153
interruptPromise,
163154
workerWrapper.runCode(
164155
entry,
165-
(awaitchannelPromise).channel,
156+
channel,
166157
interruptBuffer,
167158
Comlink.proxy(outputCallback),
168159
Comlink.proxy(inputCallback),

‎frontend/src/Worker.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import*asComlinkfrom'comlink';
66
importpythonCoreUrlfrom"./python_core.tar.load_by_url"
77
importloadPythonStringfrom"!!raw-loader!./load.py"
8-
import{readChannel,syncSleep,uuidv4}from"sync-message";
8+
import{readMessage,syncSleep,uuidv4}from"sync-message";
99

1010
asyncfunctiongetPackageBuffer(){
1111
constresponse=awaitfetch(pythonCoreUrl);
@@ -69,7 +69,7 @@ async function runCode(entry, channel, interruptBuffer, outputCallback, inputCal
6969
constfullInputCallback=(data)=>{
7070
constmessageId=uuidv4();
7171
inputCallback(messageId,toObject(data));
72-
constresult=readChannel(channel,messageId).text;
72+
constresult=readMessage(channel,messageId).text;
7373
if(result==null){
7474
returnnull;
7575
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp