Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zhashkevych authored May 10, 2019
1 parent c4a971f commit 1728e01
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Go Scheduler helps you to manage functions that should be executed every N secon

See it in action:

## Example #1

```go
package main

Expand Down Expand Up @@ -42,4 +44,50 @@ func collectStatistics(ctx context.Context) {
fmt.Printf("stats updated at %s\n", time.Now().String())
}

```
```

## Example #2

```go
package main

import (
"context"
"fmt"
"os"
"os/signal"
"time"

"github.com/zhashkevych/scheduler"
)

func main() {
ctx := context.Background()

sc := scheduler.NewScheduler()
sc.Add(ctx, testFunc, time.Second*2)

quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)

<-quit
}

func testFunc(ctx context.Context) {
ctx, _ = context.WithTimeout(ctx, time.Second*5)

i := 0
for {
time.Sleep(time.Millisecond * 100)
i++
fmt.Printf("%d ", i)

select {
case <-ctx.Done():
fmt.Println()
return
default:
}
}
}
```

0 comments on commit 1728e01

Please sign in to comment.