batches.lua 378 B

123456789101112131415161718
  1. --[[
  2. Function to loop in batches.
  3. Just a bit of warning, some commands as ZREM
  4. could receive a maximum of 7000 parameters per call.
  5. ]]
  6. local function batches(n, batchSize)
  7. local i = 0
  8. return function()
  9. local from = i * batchSize + 1
  10. i = i + 1
  11. if (from <= n) then
  12. local to = math.min(from + batchSize - 1, n)
  13. return from, to
  14. end
  15. end
  16. end