@@ -71,21 +71,24 @@ class WorkerPool {
71
71
} ) ;
72
72
}
73
73
74
+ // TODO: we need to handle a worker that doesn't respond at all. Timeout should terminate and avoid re-creating
74
75
protected addWorker ( ) {
75
76
const worker = this . workerFactory ( ) ;
76
77
let workerError : Error ;
77
78
let initializing = true ;
78
- const messageHandler = ( result : WorkerResultInternal ) => {
79
+ const messageHandler = ( result : WorkerResultInternal | 'initialized' ) => {
79
80
if ( initializing ) {
80
- // @ts -ignore: ignoring type here
81
81
if ( result !== 'initialized' ) {
82
- throw Error ( 'TMP IMP failed to initialize properly' ) ;
82
+ throw new errors . ErrorWorkerInitializationFailed ( ) ;
83
83
}
84
84
initializing = false ;
85
85
this . freeWorkers . push ( worker ) ;
86
86
this . $workerFreed . next ( ) ;
87
87
return ;
88
88
}
89
+ if ( result === 'initialized' ) {
90
+ throw new errors . ErrorWorkersUndefinedBehaviour ( ) ;
91
+ }
89
92
if ( result . error != null ) {
90
93
worker [ taskInfoSymbol ] . done ( undefined , result . error ) ;
91
94
} else {
@@ -115,9 +118,8 @@ class WorkerPool {
115
118
) {
116
119
// If the worker errored then we want to check if it was a failure to load error
117
120
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 ( ) ;
121
123
this . cleanUp ( this . terminatedError ) ;
122
124
}
123
125
return ;
@@ -127,13 +129,6 @@ class WorkerPool {
127
129
worker . once ( 'online' , async ( ) => {
128
130
worker . postMessage ( { type : 'initialize' , data : undefined } ) ;
129
131
} ) ;
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));
137
132
this . workers . add ( worker ) ;
138
133
this . $workerCreated . next ( ) ;
139
134
}
@@ -158,7 +153,7 @@ class WorkerPool {
158
153
159
154
public async terminate ( force : boolean ) {
160
155
if ( this . terminatedError != null ) return ;
161
- this . terminatedError = Error ( 'TMP IMP terminating' ) ;
156
+ this . terminatedError = new errors . ErrorWorkerPoolWorkerTerminated ( ) ;
162
157
// Prevent new tasks and wait for exising queue to drain
163
158
if ( ! force ) await this . settled ( ) ;
164
159
// Prevent terminations from creating new workers
0 commit comments