spawn-with-kill.js 810 B

1234567891011121314151617181920212223242526
  1. /**
  2. * @author Toru Nagashima
  3. * @copyright 2016 Toru Nagashima. All rights reserved.
  4. * See LICENSE file in root directory for full license.
  5. */
  6. 'use strict'
  7. // ------------------------------------------------------------------------------
  8. // Requirements
  9. // ------------------------------------------------------------------------------
  10. const spawn = require('../../lib/spawn')
  11. // ------------------------------------------------------------------------------
  12. // Public Interface
  13. // ------------------------------------------------------------------------------
  14. module.exports = function spawnWithKill (command, args) {
  15. return new Promise((resolve, reject) => {
  16. const cp = spawn(command, args, {})
  17. cp.on('exit', resolve)
  18. cp.on('error', reject)
  19. setTimeout(() => cp.kill(), 1000)
  20. })
  21. }