Skip to content

Instantly share code, notes, and snippets.

@daurnimator
Last active December 17, 2015 00:56
Show Gist options
  • Save daurnimator/3842dfdfd3684d297509 to your computer and use it in GitHub Desktop.
Save daurnimator/3842dfdfd3684d297509 to your computer and use it in GitHub Desktop.
turbo-cqueues.lua
local turbo = require "turbo"
local cqueues = require "cqueues"
local cq = cqueues.new()
cq:wrap(function()
while true do
print("HELLO FROM CQUEUES")
cqueues.sleep(1)
end
end)
local turbo_loop = turbo.ioloop.instance()
local turbo_timer
local function handler()
turbo_timer = nil
assert(cq:step(0))
local timeout = cq:timeout()
if timeout then
turbo_timer = turbo_loop:add_timeout(turbo.util.gettimemonotonic() + timeout, handler)
end
end
turbo_loop:add_handler(cq:pollfd(), turbo.ioloop.READ, function()
if turbo_timer then
turbo_loop:remove_timeout(turbo_timer)
end
return handler()
end)
turbo_loop:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment