Logo

Programming-Idioms

  • Go
  • C#

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
System.Threading.Tasks;
Task.Delay(5000);
using System.Threading;
Thread.Sleep(5000);

Takes an int value representing milliseconds.
import "time"
time.Sleep(5 * time.Second)

Unit is Duration, an alias for int64 representing a number of nanoseconds.
The constant Second helps readability.
delay 5.0;

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