diff options
author | Kim Alvefur <zash@zash.se> | 2021-12-16 12:16:45 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-12-16 12:16:45 +0100 |
commit | 081647ea1ffaf7bf932e727c9311e765b642da5b (patch) | |
tree | de2384b2981bf7c5f94fe5ca3547bb09b86a984e /util/smqueue.lua | |
parent | 81d747b6a48402d86b97442866842e4feffca8b9 (diff) | |
download | prosody-081647ea1ffaf7bf932e727c9311e765b642da5b.tar.gz prosody-081647ea1ffaf7bf932e727c9311e765b642da5b.zip |
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
There was an off-by-one in the modulo calculation. Switching to a plain
old array-table makes the apparent size of the queue wrong, but since
some of the queue may not be available this is likely for the best.
Diffstat (limited to 'util/smqueue.lua')
-rw-r--r-- | util/smqueue.lua | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/util/smqueue.lua b/util/smqueue.lua index d24c35ae..6d8348d4 100644 --- a/util/smqueue.lua +++ b/util/smqueue.lua @@ -38,17 +38,12 @@ function smqueue:resume() return self._queue:items() end function smqueue:consume() return self._queue:consume() end -local compat_mt = {} - -function compat_mt:__index(i) - if i < self._queue._tail then return nil end - return self._queue._queue._items[(i + self._queue._tail) % self._queue._queue.size] +function smqueue:table() + local t = {}; + for i, v in self:resume() do t[i] = v; end + return t end -function compat_mt:__len() return self._queue:count_unacked() end - -function smqueue:table() return setmetatable({ _queue = self }, compat_mt) end - local function freeze(q) return { head = q._head; tail = q._tail } end local queue_mt = { __name = "smqueue"; __index = smqueue; __len = smqueue.count_unacked; __freeze = freeze } |