Skip to content

Commit fae4df4

Browse files
committed
Add Sleep For A Duration as a go til
1 parent db8cb93 commit fae4df4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
77
warrant a full blog post. These are mostly things I learn by pairing with
88
smart people at [Hashrocket](http://hashrocket.com/).
99

10-
_324 TILs and counting..._
10+
_325 TILs and counting..._
1111

1212
---
1313

@@ -103,6 +103,7 @@ _324 TILs and counting..._
103103

104104
- [Not So Random](go/not-so-random.md)
105105
- [Replace The Current Process With An External Command](go/replace-the-current-process-with-an-external-command.md)
106+
- [Sleep For A Duration](go/sleep-for-a-duration.md)
106107

107108
### javascript
108109

go/sleep-for-a-duration.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Sleep For A Duration
2+
3+
Many languages allow you to sleep for a certain number of milliseconds. In
4+
those languages, you can give `500` or `1000` to the sleep function to
5+
sleep for half a second and a second respectively. In Go, the duration of a
6+
call to [`time.Sleep`](https://golang.org/pkg/time/#Sleep) is in
7+
nanoseconds. Fortunately, there are constants that make it easy to sleep in
8+
terms of milliseconds.
9+
10+
For example, you can sleep for a half a second (500 milliseconds) like so:
11+
12+
```go
13+
package main
14+
15+
import (
16+
"time"
17+
)
18+
19+
func main() {
20+
time.Sleep(500 * time.Millisecond)
21+
}
22+
```
23+
24+
Other available time constants are `Nanosecond`, `Microsecond`, `Second`,
25+
`Minute`, `Hour`.

0 commit comments

Comments
 (0)