Last active
December 17, 2015 00:56
-
-
Save daurnimator/3842dfdfd3684d297509 to your computer and use it in GitHub Desktop.
turbo-cqueues.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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