jsbin/lib/processors/fork.js
Remy Sharp bacf7f923e Splitting out the processors and supporting zmq
Note that zmq is used in production along side Pennyworth.
2014-05-22 12:40:03 +01:00

32 lines
736 B
JavaScript

'use strict';
var RSVP = require('rsvp');
var fork = require('child_process').fork;
module.exports = function (language, source) {
return new RSVP.Promise(function (resolve) {
var child = fork(__dirname);
var output = '';
var timeout = setTimeout(function () {
console.error(language + ' processor timeout');
child.kill();
}, 1000);
child.on('stderr', function (data) {
console.error(language + ' processor errors');
console.error(data);
});
child.on('message', function (message) {
output += message;
});
child.on('exit', function () {
clearTimeout(timeout);
resolve(output);
});
child.send({ language: language, source: source });
});
};