diff options
author | ubq323 <ubq323@ubq323.website> | 2025-02-25 23:43:41 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2025-02-25 23:43:41 +0000 |
commit | 4dec20e4ff11b61be57a6cfbdb289327d9e1eb7d (patch) | |
tree | cc2ffe0357c1110236270ad46dc2006cdb01bf89 /queue.lua | |
parent | e03937bbe51f3dd8e0d8ecc732999f5c4578fa94 (diff) |
the Restructuring
Diffstat (limited to 'queue.lua')
-rw-r--r-- | queue.lua | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/queue.lua b/queue.lua deleted file mode 100644 index 8c9c373..0000000 --- a/queue.lua +++ /dev/null @@ -1,39 +0,0 @@ -local cqueues = require'cqueues' -local condition = require'cqueues.condition' -local cqaux = require'cqueues.auxlib' - -local Queue = {} - -function Queue.make() - return setmetatable({ - items = {}, - cv = condition.new(), - }, {__index=Queue}) -end - -function Queue.enqueue(self, ...) - local item = table.pack(...) - table.insert(self.items, item) - if #self.items > 128 then - print('warning: queue is quite big') - end - self.cv:signal() -end - -function Queue.iter(self) - return cqaux.wrap(function() - while true do - while #self.items > 0 do - local items = self.items - self.items = {} -- the old switcheroo - for _, item in ipairs(items) do - coroutine.yield(table.unpack(item, 1, item.n)) - end - end - self.cv:wait() - end - end) -end - - -return Queue |