diff --git a/README.md b/README.md index 90b28b0..456d5d9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really warrant a full blog post. These are mostly things I learn by pairing with smart people at [Hashrocket](http://hashrocket.com/). -_324 TILs and counting..._ +_325 TILs and counting..._ --- @@ -103,6 +103,7 @@ _324 TILs and counting..._ - [Not So Random](go/not-so-random.md) - [Replace The Current Process With An External Command](go/replace-the-current-process-with-an-external-command.md) +- [Sleep For A Duration](go/sleep-for-a-duration.md) ### javascript diff --git a/go/sleep-for-a-duration.md b/go/sleep-for-a-duration.md new file mode 100644 index 0000000..0754463 --- /dev/null +++ b/go/sleep-for-a-duration.md @@ -0,0 +1,25 @@ +# Sleep For A Duration + +Many languages allow you to sleep for a certain number of milliseconds. In +those languages, you can give `500` or `1000` to the sleep function to +sleep for half a second and a second respectively. In Go, the duration of a +call to [`time.Sleep`](https://golang.org/pkg/time/#Sleep) is in +nanoseconds. Fortunately, there are constants that make it easy to sleep in +terms of milliseconds. + +For example, you can sleep for a half a second (500 milliseconds) like so: + +```go +package main + +import ( + "time" +) + +func main() { + time.Sleep(500 * time.Millisecond) +} +``` + +Other available time constants are `Nanosecond`, `Microsecond`, `Second`, +`Minute`, `Hour`.