Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ jobs:
run: staticcheck ./...

- name: Run gofumpt
if: matrix.platform != 'windows-latest' # :<
run: gofumpt -d -e -l .

- name: Run revive
run: revive --formatter=stylish ./...

- name: Run go test
run: go test -v -race ./...
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# run

[![GoDoc](https://godoc.org/github.com/oklog/run?status.svg)](https://godoc.org/github.com/oklog/run)
[![GoDoc](https://godoc.org/github.com/oklog/run?status.svg)](https://godoc.org/github.com/oklog/run)
[![test](https://github.com/oklog/run/actions/workflows/test.yaml/badge.svg?branch=main&event=push)](https://github.com/oklog/run/actions/workflows/test.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/oklog/run)](https://goreportcard.com/report/github.com/oklog/run)
[![Apache 2 licensed](https://img.shields.io/badge/license-Apache2-blue.svg)](https://raw.githubusercontent.com/oklog/run/master/LICENSE)
Expand All @@ -16,8 +16,8 @@ finally returns control to the caller only once all actors have returned. This
general-purpose API allows callers to model pretty much any runnable task, and
achieve well-defined lifecycle semantics for the group.

run.Group was written to manage component lifecycles in func main for
[OK Log](https://github.com/oklog/oklog).
run.Group was written to manage component lifecycles in func main for
[OK Log](https://github.com/oklog/oklog).
But it's useful in any circumstance where you need to orchestrate multiple
goroutines as a unit whole.
[Click here](https://www.youtube.com/watch?v=LHe1Cb_Ud_M&t=15m45s) to see a
Expand Down Expand Up @@ -62,14 +62,30 @@ g.Add(func() error {
})
```

### http.Server graceful Shutdown

```go
httpServer := &http.Server{
Addr: "localhost:8080",
Handler: ...,
}
g.Add(func() error {
return httpServer.ListenAndServe()
}, func(error) {
ctx, cancel := context.WithTimeout(context.TODO(), 3*time.Second)
defer cancel()
httpServer.Shutdown(ctx)
})
```

## Comparisons

Package run is somewhat similar to package
[errgroup](https://godoc.org/golang.org/x/sync/errgroup),
Package run is somewhat similar to package
[errgroup](https://godoc.org/golang.org/x/sync/errgroup),
except it doesn't require actor goroutines to understand context semantics.

It's somewhat similar to package
[tomb.v1](https://godoc.org/gopkg.in/tomb.v1) or
[tomb.v1](https://godoc.org/gopkg.in/tomb.v1) or
[tomb.v2](https://godoc.org/gopkg.in/tomb.v2),
except it has a much smaller API surface, delegating e.g. staged shutdown of
except it has a much smaller API surface, delegating e.g. staged shutdown of
goroutines to the caller.