Skip to content

Commit

Permalink
make worker_url const to fix firefox review warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
xmcp committed Apr 7, 2024
1 parent e538862 commit 5abcabd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions pakkujs/core/worker_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ interface WebWorkerLike {
terminate: ()=>void;
}

const WORKER_URL = chrome.runtime.getURL('/generated/combine_worker.js');

export class WorkerMaker {
url: string;
use_simulated: boolean;

worker_blob_url: string | null;
fallback_fn: ((...args: ArgsType)=>RetType) | null;
constructor(url: string) {
this.url = url;
constructor() {
this.use_simulated = false;
this.worker_blob_url = null;
this.fallback_fn = null;
Expand All @@ -42,7 +42,7 @@ export class WorkerMaker {
return this._spawn_simulated();

if(!this.worker_blob_url) {
let src = await (await fetch(this.url)).text();
let src = await (await fetch(WORKER_URL)).text();
// remove `export { do_combine };`
src = src.replace(/\bexport\s*\{\s*[a-zA-Z0-9_]+\s*}/, '');

Expand All @@ -62,7 +62,7 @@ export class WorkerMaker {

async _spawn_simulated(): Promise<WebWorkerLike> {
if(!this.fallback_fn) {
let module = await import(this.url);
let module = await import(WORKER_URL);
this.fallback_fn = module[FUNCTION_NAME] as (...args: ArgsType)=>RetType;
}

Expand Down Expand Up @@ -105,8 +105,7 @@ export class WorkerPool {
async spawn() {
console.log('pakku worker pool: spawn', this.pool_size, 'workers');

let url = chrome.runtime.getURL('/generated/combine_worker.js');
let maker = new WorkerMaker(url);
let maker = new WorkerMaker();
if(this.pool_size===1)
maker.use_simulated = true;

Expand Down
2 changes: 1 addition & 1 deletion pakkujs/page/troubleshooting.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ chrome.tabs.query({}, function(tabs) {
});

async function test_worker() {
let maker = new WorkerMaker(chrome.runtime.getURL('/generated/combine_worker.js'));
let maker = new WorkerMaker();
await maker.spawn();
debug.textContent += '\n\n**Worker is Simulated:** `' + maker.use_simulated + '`';
}
Expand Down

0 comments on commit 5abcabd

Please sign in to comment.