Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Lua

Idiom #45 Pause execution for 5 seconds

Sleep for 5 seconds in current thread, before proceeding with the next instructions.

The pedestrian walks, then stays still for 5 seconds, then resumes walking
local start = os.clock()
while os.clock() - start < 5 do end

Warning: this is busy-looping, which is very inefficient.
os.execute(package.config:sub(1,1) == "/" and "sleep 5" or "timeout 5")

Checks the path delimiter to tell the OS, then executes the appropriate sleep command.
delay 5.0;

New implementation...
< >
programming-idioms.org