opus/sys/modules/opus/bulkget.lua

34 lines
548 B
Lua
Raw Permalink Normal View History

local Util = require('opus.util')
2019-03-06 21:56:41 +00:00
local parallel = _G.parallel
local BulkGet = { }
function BulkGet.download(list, callback)
2019-06-18 19:19:24 +00:00
local t = { }
local failed = false
2019-03-06 21:56:41 +00:00
2019-06-18 19:19:24 +00:00
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
2019-03-06 21:56:41 +00:00
2019-06-18 19:19:24 +00:00
parallel.waitForAll(table.unpack(t))
2019-03-06 21:56:41 +00:00
end
return BulkGet