File tree Expand file tree Collapse file tree 2 files changed +13
-21
lines changed
packages/sdk/src/signature Expand file tree Collapse file tree 2 files changed +13
-21
lines changed Original file line number Diff line number Diff line change @@ -9,30 +9,25 @@ import type { SignatureValidationWorkerApi } from './SignatureValidationWorker.j
99import { StreamMessage } from '../protocol/StreamMessage.js'
1010
1111export default class BrowserSignatureValidation implements SignatureValidationContext {
12- private worker : Worker | null = null
13- private workerApi : Comlink . Remote < SignatureValidationWorkerApi > | null = null
12+ private worker : Worker
13+ private workerApi : Comlink . Remote < SignatureValidationWorkerApi >
1414
15- private ensureWorker ( ) : Comlink . Remote < SignatureValidationWorkerApi > {
16- if ( ! this . workerApi ) {
17- // Webpack 5 handles this pattern automatically, creating a separate chunk for the worker
18- this . worker = new Worker (
19- /* webpackChunkName: "signature-worker" */
20- new URL ( './SignatureValidationWorker.js' , import . meta. url )
21- )
22- this . workerApi = Comlink . wrap < SignatureValidationWorkerApi > ( this . worker )
23- }
24- return this . workerApi
15+ constructor ( ) {
16+ // Webpack 5 handles this pattern automatically, creating a separate chunk for the worker
17+ this . worker = new Worker (
18+ /* webpackChunkName: "signature-worker" */
19+ new URL ( './SignatureValidationWorker.js' , import . meta. url )
20+ )
21+ this . workerApi = Comlink . wrap < SignatureValidationWorkerApi > ( this . worker )
2522 }
2623
2724 async validateSignature ( message : StreamMessage ) : Promise < SignatureValidationResult > {
28- return this . ensureWorker ( ) . validateSignature ( message )
25+ return this . workerApi . validateSignature ( message )
2926 }
3027
3128 destroy ( ) : void {
3229 if ( this . worker ) {
3330 this . worker . terminate ( )
34- this . worker = null
3531 }
36- this . workerApi = null
3732 }
3833}
Original file line number Diff line number Diff line change @@ -6,13 +6,10 @@ import * as Comlink from 'comlink'
66import { validateSignatureData , SignatureValidationResult } from './signatureValidation'
77import { StreamMessage } from '../protocol/StreamMessage'
88
9- const workerApi = {
10- validateSignature : async ( data : StreamMessage ) : Promise < SignatureValidationResult > = > {
9+ export class SignatureValidationWorkerApi {
10+ async validateSignature ( data : StreamMessage ) : Promise < SignatureValidationResult > {
1111 return validateSignatureData ( data )
1212 }
1313}
1414
15- export type SignatureValidationWorkerApi = typeof workerApi
16-
17- Comlink . expose ( workerApi )
18-
15+ Comlink . expose ( SignatureValidationWorkerApi )
You can’t perform that action at this time.
0 commit comments