mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
message queue
This commit is contained in:
parent
b10a8d9479
commit
991c855c11
48
supervisor/mqueue.lua
Normal file
48
supervisor/mqueue.lua
Normal file
@ -0,0 +1,48 @@
|
||||
--
|
||||
-- Message Queue
|
||||
--
|
||||
|
||||
TYPE = {
|
||||
COMMAND = 0,
|
||||
PACKET = 1
|
||||
}
|
||||
|
||||
function new()
|
||||
local queue = {}
|
||||
|
||||
local length = function ()
|
||||
return #queue
|
||||
end
|
||||
|
||||
local empty = function ()
|
||||
return #queue == 0
|
||||
end
|
||||
|
||||
local _push = function (qtype, message)
|
||||
table.insert(queue, { qtype = qtype, message = message })
|
||||
end
|
||||
|
||||
local push_packet = function (message)
|
||||
push(TYPE.PACKET, message)
|
||||
end
|
||||
|
||||
local push_command = function (message)
|
||||
push(TYPE.COMMAND, message)
|
||||
end
|
||||
|
||||
local pop = function ()
|
||||
if #queue > 0 then
|
||||
return table.remove(queue)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
length = length,
|
||||
empty = empty,
|
||||
push_packet = push_packet,
|
||||
push_command = push_command,
|
||||
pop = pop
|
||||
}
|
||||
end
|
Loading…
Reference in New Issue
Block a user