finished.js 419 B

1234567891011121314151617
  1. 'use strict'
  2. const BB = require('bluebird')
  3. module.exports = function (child, hasExitCode = false) {
  4. return BB.fromNode(function (cb) {
  5. child.on('error', cb)
  6. child.on(hasExitCode ? 'close' : 'end', function (exitCode) {
  7. if (exitCode === undefined || exitCode === 0) {
  8. cb()
  9. } else {
  10. let err = new Error('exited with error code: ' + exitCode)
  11. cb(err)
  12. }
  13. })
  14. })
  15. }