Add examples to readme

This commit is contained in:
2018-06-17 13:56:44 +02:00
parent df01f2eed7
commit 0df8b1ec84
2 changed files with 32 additions and 2 deletions
+32 -1
View File
@@ -1 +1,32 @@
# Go tool belt
# Gobelt
Gobelt is a collection of Go tools.
### Thread pool
```go
import "github.com/localhots/gobelt/threadpool"
```
```go
ctx := context.Background()
pool := threadpool.New(5)
pool.Enqueue(ctx, func() {
fmt.Println("Hello")
})
pool.Close()
```
### File cache
```go
import "github.com/localhots/gobelt/filecache"
```
```go
var val int
filecache.Load(&val, "path/to/cachefile", func() interface{} {
// Expensive calls here
return 100
})
```
-1
View File
@@ -19,7 +19,6 @@ func TestFileCache(t *testing.T) {
if err != nil {
t.Fatalf("Error occurred while loading cache: %v", err)
}
if res != exp {
t.Errorf("Expected %d, got %d", exp, res)
}