Examples using... time.Second
Recent
Truncate returns the result of rounding t down to a multiple of d (since the zero time).
If d <= 0, Truncate returns t stripped of any monotonic clock reading but otherwise unchanged.
Round returns the result of rounding t to the nearest multiple of d (since the zero time).
The rounding behavior for halfway values is to round up.
If d <= 0, Round returns t stripped of any monotonic clock reading but otherwise unchanged.
Add returns the time t+d.
Tick is a convenience wrapper for NewTicker providing access to the ticking
channel only. While Tick is useful for clients that have no need to shut down
the Ticker, be aware that without a way to shut it down the underlying
Ticker cannot be recovered by the garbage collector; it "leaks".
Unlike New...
NewTicker returns a new Ticker containing a channel that will send the
time with a period specified by the duration argument.
It adjusts the intervals or drops ticks to make up for slow receivers.
The duration d must be greater than zero; if not, NewTicker will panic.
Stop the ticker to release asso...
Truncate returns the result of rounding d toward zero to a multiple of m.
If m <= 0, Truncate returns d unchanged.
Round returns the result of rounding d to the nearest multiple of m.
The rounding behavior for halfway values is to round away from zero.
If the result exceeds the maximum (or minimum)
value that can be stored in a Duration,
Round returns the maximum (or minimum) duration.
If m <= 0, Round returns d...
After waits for the duration to elapse and then sends the current time
on the returned channel.
It is equivalent to NewTimer(d).C.
The underlying Timer is not recovered by the garbage collector
until the timer fires. If efficiency is a concern, use NewTimer
instead and call Timer.Stop if the timer i...
The following example shows how to use Value for periodic program config updates
and propagation of the changes to worker goroutines.
Package sql provides a generic interface around SQL (or SQL-like)
databases.
Package sql provides a generic interface around SQL (or SQL-like)
databases.
PingContext verifies a connection to the database is still alive,
establishing a connection if necessary.
This example passes a context with a timeout to tell a blocking function that
it should abandon its work after the timeout elapses.
This example passes a context with an arbitrary deadline to tell a blocking
function that it should abandon its work as soon as it gets to it.
Here we use the built-in synchronization features of goroutines and channels to achieve synchronized access to shared state. This channel-based approach aligns with Go’s ideas of sharing memory by communicating and having each piece of data owned by exactly 1 goroutine.
Timers represent a single event in the future. You tell the timer how long you want to wait, and it provides a channel that will be notified at that time.
Implementing timeouts in Go is easy and elegant thanks to channels and select.
Go’s select lets you wait on multiple channel operations. Combining goroutines and channels with select is a powerful feature of Go.
To wait for multiple goroutines to finish, we can use a wait group.
We can use channels to synchronize execution across goroutines. Here’s an example of using a blocking receive to wait for a goroutine to finish.
A goroutine is a lightweight thread of execution.