summaryrefslogtreecommitdiff
path: root/downloader.lua
diff options
context:
space:
mode:
Diffstat (limited to 'downloader.lua')
-rw-r--r--downloader.lua17
1 files changed, 12 insertions, 5 deletions
diff --git a/downloader.lua b/downloader.lua
index a8519dd..7881129 100644
--- a/downloader.lua
+++ b/downloader.lua
@@ -6,11 +6,13 @@ local downloader = {}
local mt = {}
mt.__index = mt
-function downloader.new()
- return setmetatable({
- pending = {},
- running = false,
- }, mt)
+function downloader.new(t)
+ t = setmetatable(t or {}, mt)
+
+ t.pending = {}
+ t.running = false
+
+ return t
end
function mt:exec(url, file, cb)
@@ -60,6 +62,11 @@ end
-- likely to be used for the current display state
function mt:schedule(...)
if self.running then
+ if self.limit and #self.pending >= self.limit then
+ -- remove oldest
+ table.remove(self.pending, 1)
+ end
+
self.pending[#self.pending+1] = {...}
else
self:exec(...)