Skip to content

tm.queue ​

A general purpose job queue. Server only. This is a data structure, not the connection queue: groups wait in order and one is offered to your handler on a timer.

lua
local queue = tm.queue.create({
    interval = 2,                                   -- minutes between automatic pushes (default 1)
    onGroupSelected = function(groupId, job)        -- return true to accept, false to skip to the next group
        return startJob(groupId, job)
    end,
    onGroupAdded    = function(groupId, job) end,   -- optional
    onGroupRemoved  = function(groupId, job) end,
    onQueueUpdated  = function(groups) end,         -- the live ordered list of { groupId, job } (do not edit it)
    onQueuePaused   = function() end,
    onQueueResumed  = function() end,
})

queue:add('crew_12', 'heist')        -- back of the line
queue:add('crew_13', 'heist', 1)     -- front

tm.queue.create(props) adds the methods to the table you pass and returns it, so you can keep your own fields on it. It also starts one timer thread that wakes once a second. Callbacks are plain functions (no self), and an error inside one is logged and swallowed.

Methods ​

MethodNotes
add(groupId, job, position?)Adds a group. A position outside the list is clamped. Returns index, total. The same groupId can be added twice, use checkGroup to avoid it.
remove(groupId)Removes the first matching group. Returns whether one was removed.
push(position?)Offers groups to onGroupSelected in order starting at position (default 1). The first one that returns true is removed and the push stops. A group that declines (or whose handler errors) stays in place and the next is tried. Returns whether one was selected. Runs automatically every interval minutes.
pause(), resume()While paused the timer does not count and nothing is pushed.
destroy()Stops the timer, calls onGroupRemoved for every group, and empties the queue. Safe to call twice.
total()Number of groups queued.
checkGroup(groupId)true, position or false.
modifyGroup(groupId, job)Changes a queued group's job without moving it.
getAmountOfJobs(job)How many groups are queued for that job. Works as queue:getAmountOfJobs(job) and queue.getAmountOfJobs(job).
modifyInterval(minutes)Changes the minutes between automatic pushes.

Fields: queue.id, queue.paused, queue.interval.

onGroupAdded and onGroupRemoved receive (groupId, job). The interval defaults to 1 minute.