Skip to content

Commit e47a53a

Browse files
committed
refactor 'retry' function (index.ts)
2 parents 064873c + cb95fe1 commit e47a53a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ function retry(
2828
archive: string
2929
) {
3030
// Start the command
31-
let executables = ['7z', '7za'];
32-
const runner = () => Run(executables.shift(), command, options, override)
31+
const executables = ['7z', '7za']; // Two or more items
32+
let position = 0;
33+
const runner = () => Run(executables[position], command, options, override)
3334
.progress((data: any) => progress(onprogress(data)))
3435
.then((args: string[]) => resolve(args)) // When all is done resolve the Promise.
3536
.catch((err: any) => { // Catch the error and pass it to the reject function of the Promise.
36-
if (!executables.length) return reject(err);
37-
console.error(archive + ' failed using `' + executables[0] +
38-
'`, retrying with `' + executables[1] + '`.');
37+
if (position === executables.length - 1) return reject(err);
38+
console.error(archive + ' failed using `' + executables[position] +
39+
'`, retrying with `' + executables[position + 1] + '`.');
40+
position++;
3941
runner();
4042
});
4143
return runner();

0 commit comments

Comments
 (0)