From 58bc96236c25193450624d392955e3b9453e1934 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 12 Sep 2018 19:21:10 +0200 Subject: fetch indexes async --- generate-json.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/generate-json.lua b/generate-json.lua index 0d7fcb9..f8448ba 100755 --- a/generate-json.lua +++ b/generate-json.lua @@ -6,6 +6,7 @@ local json = require("cjson") local utils = require("utils") local conf = require("config") +local cqueues = require("cqueues") ---- -- convert apkindex list to a table @@ -120,15 +121,19 @@ function process_mirrors() local res = {} local mirrors = get_mirrors(utils.read_file(conf.mirrors_yaml)) --local mirrors = json.decode(utils.read_file(conf.mirrors_json)) + local loop = cqueues.new() for idx,mirror in ipairs(mirrors) do - local start_time = os.time() - res[idx] = {} - res[idx].url = mirror - msg(("[%s/%s] Getting indexes from mirror: %s"):format(idx, - #mirrors, mirror)) - res[idx].branch, res[idx].count = check_apkindexes(mirror) - res[idx].duration = os.difftime(os.time(),start_time) + loop:wrap(function() + local start_time = os.time() + res[idx] = {} + res[idx].url = mirror + msg(("[%s/%s] Getting indexes from mirror: %s"):format(idx, + #mirrors, mirror)) + res[idx].branch, res[idx].count = check_apkindexes(mirror) + res[idx].duration = os.difftime(os.time(),start_time) + end) end + loop:loop() return res end -- cgit v1.2.3