From 7dc3f70762a206d1a3963db2f3ad970f93e4b1f8 Mon Sep 17 00:00:00 2001 From: Felipe Andrada Date: Mon, 30 Nov 2020 02:14:21 -0300 Subject: [PATCH] fix: put timeout check in the right location --- vimeomaster.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vimeomaster.js b/vimeomaster.js index 3c299cf..4ad704b 100644 --- a/vimeomaster.js +++ b/vimeomaster.js @@ -107,7 +107,7 @@ function combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag `Downloading ${type} segment ${i}/${segmentsUrl.length} of ${filename}` ); - https + let req = https .get(segmentsUrl[i], res => { res.on("data", d => output.write(d)); @@ -118,12 +118,17 @@ function combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag .on("error", e => { cb(e); }); + + req.setTimeout(7000, function () { + log("⚠️", 'Timeout. Retrying'); + combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag, cb); + }); } function getJson(url, cb) { let data = ""; - let req = https + https .get(url, res => { res.on("data", d => (data += d)); @@ -132,11 +137,6 @@ function getJson(url, cb) { .on("error", e => { cb(e); }); - - req.setTimeout(7000, function () { - log("⚠️", 'Timeout. Retrying'); - combineSegments(type, i, segmentsUrl, output, filename, downloadingFlag, cb); - }); } function initJs(n = 0) {