1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-16 05:34:49 +00:00
opus/sys/apis/bulkget.lua
kepler155c@gmail.com a4145951f7 bulk download
2019-03-06 16:56:41 -05:00

34 lines
609 B
Lua

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