Diff

teal-src/util/smqueue.tl @ 12058:4860da718e87

util.smqueue: Simplify compat table, fix dependent modules (thanks Martin) There was an off-by-one in the modulo calculation. Switching to a plain old array-table makes the apparent size of the queue wrong, but since some of the queue may not be available this is likely for the best.
author Kim Alvefur <zash@zash.se>
date Thu, 16 Dec 2021 12:16:45 +0100
parent 12057:e880f5a13080
line wrap: on
line diff
--- a/teal-src/util/smqueue.tl	Thu Dec 16 12:16:08 2021 +0100
+++ b/teal-src/util/smqueue.tl	Thu Dec 16 12:16:45 2021 +0100
@@ -70,22 +70,13 @@
 	return self._queue:consume()
 end
 
--- Compatibility wrapper, meant to look like a plain ol' array
-local record compat_mt
-	_queue : smqueue<any>
-end
-
-function compat_mt:__index(i : integer) : any
-	if i < self._queue._tail then return nil end
-	return self._queue._queue._items[(i + self._queue._tail) % self._queue._queue.size];
-end
-
-function compat_mt:__len() : integer
-	return self._queue:count_unacked()
-end
-
+-- Compatibility layer, plain ol' table
 function smqueue:table() : { any }
-	return setmetatable({ _queue = self }, compat_mt);
+	local t : { any } = {};
+	for i, v in self:resume() do
+		t[i] = v;
+	end
+	return t;
 end
 
 local function freeze(q : smqueue<any>) : { string:integer }