mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-10 15:57:07 +01:00
Use async spawn() by default.
This commit is contained in:
45
src/utils/safe-spawn.js
Normal file
45
src/utils/safe-spawn.js
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
Safe spawn utility for HackMyResume / FluentCV.
|
||||
@module safe-spawn.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
module.exports = function( cmd, args, isSync ) {
|
||||
|
||||
try {
|
||||
|
||||
var spawn = require('child_process')[ isSync? 'spawnSync' : 'spawn'];
|
||||
var info = spawn( cmd, args );
|
||||
|
||||
if( !isSync ) {
|
||||
info.on('error', function(err) {
|
||||
throw {
|
||||
cmd: 'wkhtmltopdf',
|
||||
inner: err
|
||||
};
|
||||
});
|
||||
}
|
||||
else {
|
||||
if( info.error ) {
|
||||
throw {
|
||||
cmd: 'wkhtmltopdf',
|
||||
inner: info.error
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch( ex ) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
Reference in New Issue
Block a user