/** * Kills and restarts the shard's process/worker. * @param {number} [delay=500] How long to wait between killing the process/worker and restarting it (in milliseconds) * @param {number} [spawnTimeout=30000] The amount in milliseconds to wait until the {@link Client} has become ready * before resolving. (-1 or Infinity for no wait) * @returns {Promise<ChildProcess>} */ async respawn(delay = 500, spawnTimeout) { this.kill(); if (delay > 0) await Util.delayFor(delay); return this.spawn(spawnTimeout); }
let zipExe = async function(dists) { return Promise.all(_.map(dists, (dist) => { let name = basename(dist); return spawn('zip', [`${PATHS.DIST}/${name}.zip`, '-r', `${PATHS.DIST}/${name}`]); })); }
function spawnDetached( cwd, command, args, output, env ) { const stdio = output ? [ 'ignore', output, output ] : null; const app = spawn( command, args, { stdio, detached: true, env, cwd } ); app.on( 'error', ( err ) => { throw `failed to initialize command "${ command }": "${ err }"`; } ); return app; }
let releaseCommit = async function() { let {v} = argv; if(['major', 'minor', 'patch'].indexOf(v) === -1) { v = 'patch'; } Config.version = semver.inc(Config.version, v); let newConfig = JSON.stringify(Config, null, 2); // update package.json writeFileSync('package.json', newConfig); await spawn('git', ['commit', '-m', `Release v${Config.version}`, 'package.json']); await spawn('git', ['push']); }
test.cb('default', t => { // TODO: Use `execa` here when the `spawn` API is done const cp = childProcess.spawn('./cli.js', {stdio: 'inherit'}); cp.on('error', t.fail); cp.on('close', code => { t.is(code, 0); t.end(); }); });
ipc.on('openExternalPlayer', (e, ...args) => { const externalPlayer = require('./external-player') const thumbar = require('./thumbar') menu.togglePlaybackControls(false) thumbar.disable() externalPlayer.spawn(...args) })
async createService(name, ...args) { const fileName = path.join(__dirname, '..', 'services', name); const handle = await rpc_process.spawn(fileName, ...args); this._handles.push(handle); return handle; }
test("Taskr.plugin (export fn params)", co(function * (t) { t.plan(3) const taskr = yield cli.spawn(altDir) taskr.tasks = { foo: { data: [], func: co(function * (f) { yield f.localPlugin({ t }) }) } } yield taskr.start("foo") }))
schnackEvents.on('new-comment', event => { const body = createEmailBody(config, event); try { const sendmail = spawn('sendmail', [notify.sendmail.to]); sendmail.stdin.write(body); sendmail.stdin.end(); } catch (error) { console.error('Error sending sendmail notification:', error); } });
let spawn = async function(command, args, options) { let cb = (resolve, reject) => { let exe = ChildProcess.spawn(command, args, options); exe.stdout.on('data', (data) => $.util.log(data.toString('utf8').trim())); exe.stderr.on('data', (err) => onError(err.toString('utf8'))); exe.on('close', resolve); exe.on('error', reject); }; return new Promise(cb); }
const executeCommand = (command, args) => { const child = spawn(command, args, { stdio: 'inherit' }); return new Promise((resolve, reject) => { child.on('close', code => { if (code !== 0) { reject(new Error(`${command} ${args.join(' ')} failed with exit code ${code}`)); return; } resolve(); }); }); }
test.cb('remove temporary files on cancel', t => { t.plan(1); const cp = spawn('../cli.js', ['https://sindresorhus.com', '320x240']); cp.on('exit', () => { t.false(fs.existsSync('sindresorhus.com-320x240.png')); t.end(); }); setTimeout(() => { cp.kill('SIGINT'); }, 500); });
test('kill from port', async t => { const port = await getPort(); const {pid} = childProcess.spawn('node', ['fixture.js', port]); await execa('./cli.js', ['--force', pid]); await noopProcessKilled(t, pid); });
test.cb('main', t => { const cp = childProcess.spawn('./cli.js', {stdio: 'inherit'}); cp.on('error', t.fail); cp.on('close', code => { t.is(code, 0); t.end(); }); });
function executeCommand(command, args, options = {}) { const child = spawn(command, args, { stdio: 'inherit', ...options }); return new Promise((resolve, reject) => { child.on('close', (code) => { if (code !== 0) { reject(new Error(`${command} ${args.join(' ')} failed with exit code ${code}. Please check your console.`)); return; } resolve(); }); }); }