11# run
22
3- [ ![ GoDoc] ( https://godoc.org/github.com/oklog/run?status.svg )] ( https://godoc.org/github.com/oklog/run )
3+ [ ![ GoDoc] ( https://godoc.org/github.com/oklog/run?status.svg )] ( https://godoc.org/github.com/oklog/run )
44[ ![ 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 )
55[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/oklog/run )] ( https://goreportcard.com/report/github.com/oklog/run )
66[ ![ Apache 2 licensed] ( https://img.shields.io/badge/license-Apache2-blue.svg )] ( https://raw.githubusercontent.com/oklog/run/master/LICENSE )
@@ -16,8 +16,8 @@ finally returns control to the caller only once all actors have returned. This
1616general-purpose API allows callers to model pretty much any runnable task, and
1717achieve well-defined lifecycle semantics for the group.
1818
19- run.Group was written to manage component lifecycles in func main for
20- [ OK Log] ( https://github.com/oklog/oklog ) .
19+ run.Group was written to manage component lifecycles in func main for
20+ [ OK Log] ( https://github.com/oklog/oklog ) .
2121But it's useful in any circumstance where you need to orchestrate multiple
2222goroutines as a unit whole.
2323[ Click here] ( https://www.youtube.com/watch?v=LHe1Cb_Ud_M&t=15m45s ) to see a
@@ -62,14 +62,30 @@ g.Add(func() error {
6262})
6363```
6464
65+ ### http.Server graceful Shutdown
66+
67+ ``` go
68+ httpServer := &http.Server {
69+ Addr : " localhost:8080" ,
70+ Handler : ...,
71+ }
72+ g.Add (func () error {
73+ return httpServer.ListenAndServe ()
74+ }, func (error ) {
75+ ctx , cancel := context.WithTimeout (context.TODO (), 3 *time.Second )
76+ defer cancel ()
77+ httpServer.Shutdown (ctx)
78+ })
79+ ```
80+
6581## Comparisons
6682
67- Package run is somewhat similar to package
68- [ errgroup] ( https://godoc.org/golang.org/x/sync/errgroup ) ,
83+ Package run is somewhat similar to package
84+ [ errgroup] ( https://godoc.org/golang.org/x/sync/errgroup ) ,
6985except it doesn't require actor goroutines to understand context semantics.
7086
7187It's somewhat similar to package
72- [ tomb.v1] ( https://godoc.org/gopkg.in/tomb.v1 ) or
88+ [ tomb.v1] ( https://godoc.org/gopkg.in/tomb.v1 ) or
7389[ tomb.v2] ( https://godoc.org/gopkg.in/tomb.v2 ) ,
74- except it has a much smaller API surface, delegating e.g. staged shutdown of
90+ except it has a much smaller API surface, delegating e.g. staged shutdown of
7591goroutines to the caller.
0 commit comments