@@ -21,17 +21,17 @@ export function startWorker() {
2121        child  =  spawn ( node ,  [ 
2222            // '--debug', // Uncomment if you want to debug the child process 
2323            __dirname  +  '/workerProcess.js' , 
24-         ] ,  {  env } ) ; 
24+         ] ,  {  env : env ,   stdio : [ 'ipc' ]    } ) ; 
2525
2626        child . on ( 'error' , ( err )  =>  { 
2727            console . log ( 'CHILD ERR:' ,  err . toString ( ) ) ; 
2828            child  =  null ; 
2929        } ) ; 
3030
3131        console . log ( 'ts worker started' ) ; 
32-         function  processResponse ( m : string )  { 
32+         function  processResponse ( m : any )  { 
3333            try  { 
34-                 var  parsed : messages . Message < any >  =  JSON . parse ( m . toString ( ) ) ; 
34+                 var  parsed : messages . Message < any >  =  m ; 
3535            } 
3636            catch  ( ex )  { 
3737                console . log ( 'PARENT ERR: Non JSON data from child:' ,  m ) ; 
@@ -45,11 +45,8 @@ export function startWorker() {
4545                delete  currentListeners [ parsed . message ] [ parsed . id ] ; 
4646            } 
4747        } 
48-         var  bufferedResponseHandler  =  new  messages . BufferedBySeperatorHandler ( processResponse ) ; 
4948
50-         child . stdout . on ( 'data' , ( m )  =>  { 
51-             bufferedResponseHandler . handle ( m ) 
52-         } ) ; 
49+         child . on ( 'message' , ( resp ) => processResponse ( resp ) ) ; 
5350
5451
5552        child . stderr . on ( 'data' , ( err )  =>  { 
@@ -101,7 +98,7 @@ function createId(): string {
10198function  query < Query ,  Response > ( message : string ,  data : Query ) : Promise < Response >  { 
10299
103100    // If we don't have a child exit 
104-     if  ( ! child   ||   ! child . stdin . writable )  { 
101+     if  ( ! child )  { 
105102        console . log ( 'PARENT ERR: no child when you tried to send :' ,  message ) ; 
106103        return ; 
107104    } 
@@ -115,7 +112,7 @@ function query<Query, Response>(message: string, data: Query): Promise<Response>
115112    currentListeners [ message ] [ id ]  =  defer ; 
116113
117114    // 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  } ) ; 
119116    return  defer . promise ; 
120117} 
121118
0 commit comments