API Reference - uv.timer

August 30, 2014 ยท View on GitHub

timer.set(timeout, callback)

Schedule a function to be called once in the future. Returns immediately.

timer.set(5000, function()
  print('Ding!')
end)
print('Waiting 5 seconds...')
loop.run()
print('The timer dinged.')

timer.every(timeout, callback)

Schedule a function to be called every timeout milliseconds. Returns immediately.

timer.every(1000, function(t)
  print('Tick...')
  if we_are_done then
    t:stop()
  end
end)
loop.run()

timer.sleep(timeout, callback)

Yield the current coroutine for timeout milliseconds.

print('Going to sleep...')
timer.sleep(5000)
print('Woke up')