Skip to content

Commit

Permalink
Don't use a worker for downloading projects
Browse files Browse the repository at this point in the history
We are not doing anything else on the main thread that would
justify spinning up a Worker. They are just another source of
possible error.
  • Loading branch information
GarboMuffin committed Jul 24, 2024
1 parent f60fe5d commit ac86917
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 118 deletions.
7 changes: 0 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@turbowarp/scratch-svg-renderer": "^1.0.0-202401111326-62c0f26",
"babel-jest": "^27.4.5",
"babel-loader": "^8.2.3",
"comlink": "^4.3.1",
"copy-webpack-plugin": "^6.4.1",
"cross-env": "^7.0.3",
"css-loader": "^5.2.7",
Expand Down
11 changes: 0 additions & 11 deletions src/build/auto-comlink-expose-loader.js

This file was deleted.

77 changes: 0 additions & 77 deletions src/build/p4-worker-loader.js

This file was deleted.

4 changes: 3 additions & 1 deletion src/packager/download-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ const mutateScratch3InPlace = (projectData) => {
optimizeSb3Json(projectData);
};

export const downloadProject = async (projectData, progressCallback = () => {}) => {
export const downloadProject = async (projectData, progressCallback = () => {}, signal) => {
let analysis = unknownAnalysis();

const options = {
signal,

onProgress(type, loaded, total) {
progressCallback(type, loaded, total);
},
Expand Down
38 changes: 17 additions & 21 deletions src/packager/load-project.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
import {transfer, proxy} from 'comlink';
import createDownloadWorker from '../build/p4-worker-loader!./download-project';
import {readAsArrayBuffer} from '../common/readers';
import request from '../common/request';
import {AbortError} from '../common/errors';

const downloadProject = async (buffer, progressCallback) => {
const {worker, terminate} = await createDownloadWorker();
let terminateAndReject;
const downloadPromise = new Promise((resolve, reject) => {
worker.downloadProject(transfer(buffer, [buffer]), proxy(progressCallback))
.then((res) => {
terminate();
resolve(res);
})
.catch((err) => {
terminate();
reject(err)
});
terminateAndReject = () => {
terminate();
reject(new AbortError());
};
});
const controller = typeof AbortController === 'function' && new AbortController();
const downloadProject = await import(/* webpackChunkName: "downloader" */ './download-project.js');
let reject;
return {
promise: downloadPromise,
terminate: terminateAndReject
promise: new Promise((_resolve, _reject) => {
reject = _reject;

downloadProject.downloadProject(buffer, progressCallback, controller && controller.signal)
.then(result => _resolve(result))
.catch(err => _reject(err));
}),

terminate: () => {
reject(new AbortError());
if (controller) {
controller.abort();
}
}
};
};

Expand Down

0 comments on commit ac86917

Please sign in to comment.