Skip to content

Commit

Permalink
Fix loading service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Feb 3, 2024
1 parent debc273 commit 3ec8f64
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/signed-api/src/signed-data-verifier-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ import workerpool, { type Pool } from 'workerpool';
let pool: Pool | undefined;

export const initializeVerifierPool = () => {
pool = workerpool.pool(`${__dirname}/signed-data-verifier.ts`, {
// Allow using the worker as a TypeScript module. See:
// https://github.com/josdejong/workerpool/issues/379#issuecomment-1580093502.
//
// Note, that the pool default settings are well set, so we are leaving that as is.
workerType: 'thread',
workerThreadOpts: {
execArgv: ['--require', 'ts-node/register'],
},
});
// Allow using the worker from TS (run in development mode) or JS files (when compiled). Note, that transpiling the
// file in development mode is done by ts-node and so it must be available.
const extension = __filename.endsWith('.ts') ? 'ts' : 'js';
// Allow using the worker as a TypeScript module. See:
// https://github.com/josdejong/workerpool/issues/379#issuecomment-1580093502.
//
// Note, that the pool default settings are well set, so we are leaving that as is.
const options =
extension === 'ts'
? {
workerThreadOpts: {
execArgv: ['--require', 'ts-node/register'],
},
}
: {};
pool = workerpool.pool(`${__dirname}/signed-data-verifier.${extension}`, options);

return pool;
};
Expand Down

0 comments on commit 3ec8f64

Please sign in to comment.