Skip to content

Commit

Permalink
Handle messageerror, remove es6, check raf only for dedicated worker
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois authored and greggman committed Jan 31, 2024
1 parent 9f6d451 commit 1aa49d9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ class WorkerHelper {
});
this._worker.onmessage = (e) => {
const {id, data} = e.data;
if (data == "messageerror") {
this._bad = true;
// resolve all existing promises
this._promisesByIdMap.forEach(({resolve}) => {
resolve({});
});
return;
}
this._messagesByIdMap.set(id, data);
this._process(id);
};
Expand Down Expand Up @@ -440,21 +448,13 @@ async function checkWorkers(workerType) {
}
}

addSupportsRow('requestAnimationFrame', rAF);
if (workerType === "dedicated") {
addSupportsRow('requestAnimationFrame', rAF);
}
addSupportsRow('transferControlToOffscreen', offscreen);
addSupportsRow('OffscreenCanvas', offscreenSupported);
addSupportsRow('CanvasRenderingContext2D', twoD);

let moduleSupport = false;
try {
const workerModule = new WorkerHelper('worker-module.js');
const data = await workerModule.getMessage('ping');
moduleSupport = true;
} catch (e) {
//
}
addSupportsRow('es6 modules', moduleSupport);

addElemToDocument(el('table', { className: 'worker' }, [
el('tbody', {}, mapLikeToTableRows(obj, false)),
]));
Expand Down
3 changes: 0 additions & 3 deletions worker-import.js

This file was deleted.

16 changes: 0 additions & 16 deletions worker-module.js

This file was deleted.

3 changes: 3 additions & 0 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ self.onconnect = function(e) {
port.onmessage = function(event) {
handleMessage.call(port, event);
};
port.onmessageerror = function() {
port.postMessage({data: 'messageerror'});
};
};

0 comments on commit 1aa49d9

Please sign in to comment.