@@ -71,21 +71,24 @@ class WorkerPool {
7171 } ) ;
7272 }
7373
74+ // TODO: we need to handle a worker that doesn't respond at all. Timeout should terminate and avoid re-creating
7475 protected addWorker ( ) {
7576 const worker = this . workerFactory ( ) ;
7677 let workerError : Error ;
7778 let initializing = true ;
78- const messageHandler = ( result : WorkerResultInternal ) => {
79+ const messageHandler = ( result : WorkerResultInternal | 'initialized' ) => {
7980 if ( initializing ) {
80- // @ts -ignore: ignoring type here
8181 if ( result !== 'initialized' ) {
82- throw Error ( 'TMP IMP failed to initialize properly' ) ;
82+ throw new errors . ErrorWorkerInitializationFailed ( ) ;
8383 }
8484 initializing = false ;
8585 this . freeWorkers . push ( worker ) ;
8686 this . $workerFreed . next ( ) ;
8787 return ;
8888 }
89+ if ( result === 'initialized' ) {
90+ throw new errors . ErrorWorkersUndefinedBehaviour ( ) ;
91+ }
8992 if ( result . error != null ) {
9093 worker [ taskInfoSymbol ] . done ( undefined , result . error ) ;
9194 } else {
@@ -115,9 +118,8 @@ class WorkerPool {
115118 ) {
116119 // If the worker errored then we want to check if it was a failure to load error
117120 if ( this . workers . size === 0 && this . terminatedError == null ) {
118- this . terminatedError = new Error (
119- 'TMP IMP Workers failed to load modules' ,
120- ) ;
121+ this . terminatedError =
122+ new errors . ErrorWorkerPoolWorkerCreationFailed ( ) ;
121123 this . cleanUp ( this . terminatedError ) ;
122124 }
123125 return ;
@@ -127,13 +129,6 @@ class WorkerPool {
127129 worker . once ( 'online' , async ( ) => {
128130 worker . postMessage ( { type : 'initialize' , data : undefined } ) ;
129131 } ) ;
130-
131- // TODO: debugging
132- // worker.on('message', (...args) => console.log('DEBUG message: ', args));
133- // worker.on('messageerror', (...args) => console.log('DEBUG messageerror: ', args));
134- // worker.on('error', (...args) => console.log('DEBUG error: ', args));
135- // worker.on('exit', (...args) => console.log('DEBUG exit: ', args));
136- // worker.on('online', (...args) => console.log('DEBUG online: ', args));
137132 this . workers . add ( worker ) ;
138133 this . $workerCreated . next ( ) ;
139134 }
@@ -158,7 +153,7 @@ class WorkerPool {
158153
159154 public async terminate ( force : boolean ) {
160155 if ( this . terminatedError != null ) return ;
161- this . terminatedError = Error ( 'TMP IMP terminating' ) ;
156+ this . terminatedError = new errors . ErrorWorkerPoolWorkerTerminated ( ) ;
162157 // Prevent new tasks and wait for exising queue to drain
163158 if ( ! force ) await this . settled ( ) ;
164159 // Prevent terminations from creating new workers
0 commit comments