Skip to content

Commit 064873c

Browse files
committed
refactor 'retry' function (index.ts)
1 parent 8fe667e commit 064873c

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/index.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,17 @@ function retry(
2828
archive: string
2929
) {
3030
// Start the command
31-
return Run('7z', command, options, override)
32-
.progress(function (data: any) {
33-
return progress(onprogress(data));
34-
}) // When all is done resolve the Promise.
35-
.then(function (args: string[]) {
36-
return resolve(args);
37-
}) // Catch the error and pass it to the reject function of the Promise.
38-
.catch(function () {
39-
console.error(archive + ' failed using `7z`, retying with `7za`.');
40-
Run('7za', command, options, override)
41-
.progress(function (data: any) {
42-
return progress(onprogress(data));
43-
})
44-
.then(function (args: string[]) {
45-
return resolve(args);
46-
})
47-
.catch(function (err: any) {
48-
return reject(err);
49-
});
31+
let executables = ['7z', '7za'];
32+
const runner = () => Run(executables.shift(), command, options, override)
33+
.progress((data: any) => progress(onprogress(data)))
34+
.then((args: string[]) => resolve(args)) // When all is done resolve the Promise.
35+
.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] + '`.');
39+
runner();
5040
});
41+
return runner();
5142
}
5243

5344
/**

0 commit comments

Comments
 (0)