Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timers never called with uv.run(uv.RUN_ONCE) #18

Closed
tbastos opened this issue Nov 25, 2015 · 2 comments
Closed

Timers never called with uv.run(uv.RUN_ONCE) #18

tbastos opened this issue Nov 25, 2015 · 2 comments

Comments

@tbastos
Copy link

tbastos commented Nov 25, 2015

Hey, I'm trying to run my event loop interleaved with uv.run() like this:

local function run()
  while step() do
    uv.run(uv.RUN_ONCE)
  end
end

But uv.run(uv.RUN_ONCE) never calls my callbacks. If I change to uv.run() the callbacks are called correctly, but then I cannot call step() every loop. Any idea why uv.RUN_ONCE doesn't work?

I could set an idle callback, but then uv.run() would never block to wait for IO, which is something I want. All I want is for step() to be called after every uv loop, and uv should block. Any idea? Neither uv.check() nor uv.prepare() worked as I expected.

Thanks for the help!

@moteus
Copy link
Owner

moteus commented Nov 25, 2015

Just tested

local uv = require "lluv"

print(uv._VERSION)
print(uv.version())

uv.timer():start(1000, function()
    print "hello"
end)

uv.timer():start(2000, function()
    print "world"
end)

local i = 0
while uv.run(uv.RUN_ONCE) > 0 do
    i = i + 1
    print(i)
end

print("!!!")

output is

0.1.3-dev
1.7.5
hello
1
2
world
!!!

@tbastos
Copy link
Author

tbastos commented Nov 25, 2015

Indeed it works 👍 There was a bug in my code, your code helped me to find it... Thanks!

@tbastos tbastos closed this as completed Nov 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants