1
0
mirror of https://github.com/kepler155c/opus synced 2025-10-22 11:17:40 +00:00

bulk download

This commit is contained in:
kepler155c@gmail.com
2019-03-06 16:56:41 -05:00
parent ce9ffa6c3a
commit a4145951f7
2 changed files with 47 additions and 2 deletions

33
sys/apis/bulkget.lua Normal file
View File

@@ -0,0 +1,33 @@
local Util = require('util')
local parallel = _G.parallel
local BulkGet = { }
function BulkGet.download(list, callback)
local t = { }
local failed = false
for _ = 1, 5 do
table.insert(t, function()
while true do
local entry = table.remove(list)
if not entry then
break
end
local s, m = Util.download(entry.url, entry.path)
if not s then
failed = true
end
callback(entry, s, m)
if failed then
break
end
end
end)
end
parallel.waitForAll(table.unpack(t))
end
return BulkGet