TaskQueue
A queue that flushes all objects at the end of the current
execution step. This works by scheduling all tasks with
task.defer.
A possible use-case is to batch all requests being sent through a RemoteEvent to help prevent calling it too many times on the same frame.
local bulletQueue = TaskQueue.new(function(bullets)
bulletRemoteEvent:FireAllClients(bullets)
end)
-- Add 3 bullets. Because they're all added on the same
-- execution step, they will all be grouped together on
-- the next queue flush, which the above function will
-- handle.
bulletQueue:Add(someBullet)
bulletQueue:Add(someBullet)
bulletQueue:Add(someBullet)
Functions
new
Constructs a new TaskQueue.
Add
TaskQueue:Add(object: T) → ()Add an object to the queue.
Clear
TaskQueue:Clear() → ()Clears the TaskQueue. This will clear any tasks that were scheduled to be flushed on the current execution frame.
queue:Add(something1)
queue:Add(something2)
queue:Clear()
Destroy
TaskQueue:Destroy() → ()Destroys the TaskQueue. Just an alias for Clear().