Go Package time: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 10: Line 10:


==<tt>time.Sleep()</tt>==
==<tt>time.Sleep()</tt>==
{{External|https://golang.org/pkg/time/#Sleep}}


* https://golang.org/pkg/time/#Sleep
Sleep pauses the current [[Go_Language_Goroutines#Overview|goroutine]] for at least the duration <code>d</code>. A negative or zero duration causes <code>Sleep</code> to return immediately:
 
Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately:


<syntaxhighlight lang='go'>
<syntaxhighlight lang='go'>

Revision as of 02:30, 1 September 2023

External

Internal

Overview

  • time.After returns a channel that after the given duration, will send current time on it. This can be used to implement a timeout with select.

time.Sleep()

https://golang.org/pkg/time/#Sleep

Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately:

import "time"
...
var secs int
secs = 10
time.Sleep(time.Duration(secs) * time.Second)

After(Duration)

The After() returns a channel that will provide a Time instance after the given duration elapses. Equivalent with NewTimer(d).C.