@@ -21,17 +21,17 @@ export function startWorker() {
21
21
child = spawn ( node , [
22
22
// '--debug', // Uncomment if you want to debug the child process
23
23
__dirname + '/workerProcess.js' ,
24
- ] , { env } ) ;
24
+ ] , { env : env , stdio : [ 'ipc' ] } ) ;
25
25
26
26
child . on ( 'error' , ( err ) => {
27
27
console . log ( 'CHILD ERR:' , err . toString ( ) ) ;
28
28
child = null ;
29
29
} ) ;
30
30
31
31
console . log ( 'ts worker started' ) ;
32
- function processResponse ( m : string ) {
32
+ function processResponse ( m : any ) {
33
33
try {
34
- var parsed : messages . Message < any > = JSON . parse ( m . toString ( ) ) ;
34
+ var parsed : messages . Message < any > = m ;
35
35
}
36
36
catch ( ex ) {
37
37
console . log ( 'PARENT ERR: Non JSON data from child:' , m ) ;
@@ -45,11 +45,8 @@ export function startWorker() {
45
45
delete currentListeners [ parsed . message ] [ parsed . id ] ;
46
46
}
47
47
}
48
- var bufferedResponseHandler = new messages . BufferedBySeperatorHandler ( processResponse ) ;
49
48
50
- child . stdout . on ( 'data' , ( m ) => {
51
- bufferedResponseHandler . handle ( m )
52
- } ) ;
49
+ child . on ( 'message' , ( resp ) => processResponse ( resp ) ) ;
53
50
54
51
55
52
child . stderr . on ( 'data' , ( err ) => {
@@ -101,7 +98,7 @@ function createId(): string {
101
98
function query < Query , Response > ( message : string , data : Query ) : Promise < Response > {
102
99
103
100
// If we don't have a child exit
104
- if ( ! child || ! child . stdin . writable ) {
101
+ if ( ! child ) {
105
102
console . log ( 'PARENT ERR: no child when you tried to send :' , message ) ;
106
103
return ;
107
104
}
@@ -115,7 +112,7 @@ function query<Query, Response>(message: string, data: Query): Promise<Response>
115
112
currentListeners [ message ] [ id ] = defer ;
116
113
117
114
// Send data to worker
118
- child . stdin . write ( JSON . stringify ( { message : message , id : id , data : data } ) + messages . BufferedBySeperatorHandler . seperator ) ;
115
+ child . send ( { message : message , id : id , data : data } ) ;
119
116
return defer . promise ;
120
117
}
121
118
0 commit comments