util filter table

This commit is contained in:
Mikayla Fischler
2022-05-16 17:11:46 -04:00
parent bdd8af1873
commit 136b09d7f2
3 changed files with 33 additions and 32 deletions

View File

@@ -66,22 +66,7 @@ txnctrl.new = function ()
-- close timed-out transactions
public.cleanup = function ()
local now = util.time()
local move_to = 1
for i = 1, public.length() do
local txn = self.list[i]
if txn ~= nil then
if txn.expiry <= now then
self.list[i] = nil
else
if self.list[move_to] == nil then
self.list[move_to] = txn
self.list[i] = nil
end
move_to = move_to + 1
end
end
end
util.filter_table(self.list, function (txn) return txn.expiry > now end)
end
-- clear the transaction list