Since Lua uses cooperative multitasking and is single-threaded in most environments, libraries like LuaSocket depend heavily on timeouts and doing small batches of work at a time.
As a Redis subscriber, I have a similar requirement, and want to receive notifications within a function call that has a max-runtime duration budget. So I set a LuaSocket timeout:
client.network.socket:settimeout(0.25)
for message, abort in client:pubsub({subscribe=topics}) do
-- Handle message and abort
if (my elapsed time budget is up) then return end
end
But the client library is currently unforgiving of LuaSocket timeout errors and treats them like a hard failure:
lua: .///mytestfile.lua:46: /usr/local/share/lua/5.2/redis.lua:271: attempt to index local 'payload' (a nil value)
Since Lua uses cooperative multitasking and is single-threaded in most environments, libraries like LuaSocket depend heavily on timeouts and doing small batches of work at a time.
As a Redis subscriber, I have a similar requirement, and want to receive notifications within a function call that has a max-runtime duration budget. So I set a LuaSocket timeout:
But the client library is currently unforgiving of LuaSocket timeout errors and treats them like a hard failure: