Logo

Programming-Idioms

  • C#
  • 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
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.
local start = os.clock()
while os.clock() - start < 5 do end

Warning: this is busy-looping, which is very inefficient.
System.Threading.Tasks;
Task.Delay(5000);
using System.Threading;
Thread.Sleep(5000);

Takes an int value representing milliseconds.
delay 5.0;

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