diff options
Diffstat (limited to 'src/keeper.lua')
-rw-r--r-- | src/keeper.lua | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/keeper.lua b/src/keeper.lua index 77bf880..1f17599 100644 --- a/src/keeper.lua +++ b/src/keeper.lua | |||
@@ -87,7 +87,6 @@ local fifo_peek = function( fifo, count) | |||
87 | end | 87 | end |
88 | 88 | ||
89 | local fifo_pop = function( fifo, count) | 89 | local fifo_pop = function( fifo, count) |
90 | if count > fifo.count then error("list is too short") end | ||
91 | local first = fifo.first | 90 | local first = fifo.first |
92 | local last = first + count - 1 | 91 | local last = first + count - 1 |
93 | local out = { unpack( fifo, first, last)} | 92 | local out = { unpack( fifo, first, last)} |
@@ -178,7 +177,7 @@ end | |||
178 | -- | 177 | -- |
179 | function receive( ud, ...) | 178 | function receive( ud, ...) |
180 | 179 | ||
181 | local data, _ = tables( ud) | 180 | local data = tables( ud) |
182 | 181 | ||
183 | for i = 1, select( '#', ...) do | 182 | for i = 1, select( '#', ...) do |
184 | local key = select( i, ...) | 183 | local key = select( i, ...) |
@@ -186,7 +185,7 @@ function receive( ud, ...) | |||
186 | if fifo and fifo.count > 0 then | 185 | if fifo and fifo.count > 0 then |
187 | local val = fifo_pop( fifo, 1) | 186 | local val = fifo_pop( fifo, 1) |
188 | if val ~= nil then | 187 | if val ~= nil then |
189 | return val, key | 188 | return val, key |
190 | end | 189 | end |
191 | end | 190 | end |
192 | end | 191 | end |
@@ -194,17 +193,20 @@ end | |||
194 | 193 | ||
195 | 194 | ||
196 | ----- | 195 | ----- |
197 | -- [val1, ... valCOUNT]= receive_batched( linda_deep_ud, batch_sentinel, key , COUNT) | 196 | -- [val1, ... valCOUNT]= receive_batched( linda_deep_ud, key , min_COUNT, max_COUNT) |
198 | -- | 197 | -- |
199 | -- Read any of the given keys, consuming the data found. Keys are read in | 198 | -- Read a single key, consuming the data found. |
200 | -- order. | ||
201 | -- | 199 | -- |
202 | receive_batched = function( ud, batch_sentinel, key, count) | 200 | receive_batched = function( ud, key, min_count, max_count) |
203 | if count > 0 then | 201 | if min_count > 0 then |
204 | local data, _ = tables( ud) | 202 | local fifo = tables( ud)[key] |
205 | local fifo = data[key] | 203 | if fifo then |
206 | if fifo and fifo.count >= count then | 204 | local fifo_count = fifo.count |
207 | return fifo_pop( fifo, count) | 205 | if fifo_count >= min_count then |
206 | max_count = max_count or min_count | ||
207 | max_count = (max_count > fifo_count) and fifo_count or max_count | ||
208 | return fifo_pop( fifo, max_count) | ||
209 | end | ||
208 | end | 210 | end |
209 | end | 211 | end |
210 | end | 212 | end |