Expand/Shrink

sleep

Definition: sleep(atom seconds)
Description: Suspend execution for the specified duration, expressed in seconds (with fractions allowed).
pwa/p2js: Not supported. It would be in direct conflict with the browser event loop and make the browser non-responsive, not a good idea.
Comments: The operating system will suspend your process and schedule other processes.

Negative values trigger a fatal exception. Attempts to sleep longer than about 24 days (ie 2,147,483 seconds), are expected to suffer an internal overflow and quietly malfunction, perhaps by sleeping for only 3 days even when you asked for 27.

There is no guarantee that control will not return prematurely, perhaps due to a particular keystroke or some system broadcast message, and equally there is no official way to deliberately interrupt a sleep operation - anything of that ilk would require a loop of several shorter sleeps with appropriate tests on each iteration.

With multiple tasks, the whole program sleeps, not just the current task. To avoid this, when multitasking is in use you should instead call task_delay(seconds).
With multiple threads, other running threads continue uninterrupted and only the calling thread sleeps. Ironically perhaps, you should note that task_delay is decidedly not thread-safe and will crash if invoked from multiple threads.
Example:
puts(1, "Waiting 15 seconds...\n")
sleep(15)
puts(1, "Done.\n")
Implementation: via :%opSleep in builtins\VM\pSleep.e (an autoinclude)
See Also: lock_file, abort, time, task_delay