diff --git a/lib/dl.js b/lib/dl.js index 37ca244..998575c 100644 --- a/lib/dl.js +++ b/lib/dl.js @@ -46,16 +46,16 @@ export const getMany = (userDb, threadMax, directory, mode) => new Promise((reso let index = 0; const get = () => { - const checkError = (proc, currentIndex, type, codeOrError) => { + const checkError = (currentIndex, type, codeOrError) => { userDb[currentIndex].logs.push(codeOrError.toString()) - if (!!proc.exitCode && userDb[currentIndex].running) { + if (typeof codeOrError === 'number' && userDb[currentIndex].running) { userDb[currentIndex].running = false; onFinish(currentIndex, type); } }; const onFinish = (currentIndex, type) => { - log(ctx, `Finished ${userDb[currentIndex].user} under ${mode} mode.${type === 'close' ? '' : ' (Closed due to ' + type}`); + log(ctx, `Finished ${userDb[currentIndex].user} under ${mode} mode.${type === 'close' ? '' : ' (Closed due to ' + type + ')'}`); --running; get(); }; @@ -73,10 +73,10 @@ export const getMany = (userDb, threadMax, directory, mode) => new Promise((reso proc.stdout.on('data', data => { userDb[currentIndex].logs.push(trimNewlinesEnd(data)); }); - proc.stderr.on('data', data => checkError(proc, currentIndex, 'stderr', trimNewlinesEnd(data))); - proc.on('close', code => onFinish(currentIndex, 'close', code)); - proc.on('error', err => checkError(proc, currentIndex, 'error', trimNewlinesEnd(err))); - proc.on('exit', code => checkError(proc, currentIndex, 'exit', code)); + proc.stderr.on('data', data => checkError(currentIndex, 'stderr', trimNewlinesEnd(data))); + proc.on('close', code => checkError(currentIndex, 'close', code)); + proc.on('error', err => checkError(currentIndex, 'error', trimNewlinesEnd(err))); + proc.on('exit', code => checkError(currentIndex, 'exit', code)); } if (running === 0) {