Callback for system worker messages. The message can be sent into multiple chunks.
// Receives a message chunck
workerProxy.onmessage = function ( event ) {
console.log( event.type +': '+ event.data );
}
Callback when the external process is terminating.
// Receives an "end" event from system worker
workerProxy.onterminated = function ( event ) {
console.log( event.type +': with exitStatus:'+ event.exitStatus );
}
Closes the input stream (stdin) of the external process.
Useful when an attempt to write in the stdin of the external process with postMessage()
is stuck. endOfInput()
will release the execution.
// Create some data to gzip
var input = new Buffer( 'abcde', 'ascii' );
// Create an asynchronous system worker
var worker = new SystemWorker( 'gzip' );
// Send the compressed file on stdin.
worker.postMessage( input );
// Note that we call endOfInput() to indicate we're done. gzip (and most program waiting data from stdin) will wait for more data until the input is explicitely closed.
worker.endOfInput();
Returns system worker information.
Write on the input stream (stdin) of the external process.
// Create an asynchronous system worker
var worker = new SystemWorker( 'gzip' );
// Send the compressed file on stdin.
worker.postMessage( 'abcde' );
// Note that we call endOfInput() to indicate we're done. gzip (and most program waiting data from stdin) will wait for more data until the input is explicitely closed.
worker.endOfInput();
Write on the input stream (stdin) of the external process.
// Create some data to gzip
var input = new Buffer( 'abcde', 'ascii' );
// Create an asynchronous system worker
var worker = new SystemWorker( 'gzip' );
// Send the compressed file on stdin.
worker.postMessage( input );
// Note that we call endOfInput() to indicate we're done. gzip (and most program waiting data from stdin) will wait for more data until the input is explicitely closed.
worker.endOfInput();
Set the type of data exchanged in the SystemWorker through the onmessage and onerror properties.
workerProxy.setBinary(true);
true
to return binary data by onmessage
and onerror
, false
otherwise.
Forces the system worker to terminate its execution.
workerProxy.terminate();
workerProxy.terminate(true, true);
(default: false
) true
if the current thread must wait for the system worker execution to end
(default: false
) true
if the system worker and all his childs must end
Wait for the end of the system worker execution.
workerProxy.wait(1000);
workerProxy.wait();
Millisecond to wait for.
Callback for system worker errors.
// Receives an error workerProxy.onerror = function ( event ) { console.log( event.type +': '+ event.data ); }