Documentation ¶
Overview ¶
Example ¶
package main import ( "context" "log" "net/http" "time" "github.com/txthinking/runnergroup" ) func main() { g := runnergroup.New() s := &http.Server{ Addr: ":9991", } g.Add(&runnergroup.Runner{ Start: func() error { return s.ListenAndServe() }, Stop: func() error { return s.Shutdown(context.Background()) }, }) s1 := &http.Server{ Addr: ":9992", } g.Add(&runnergroup.Runner{ Start: func() error { return s1.ListenAndServe() }, Stop: func() error { return s1.Shutdown(context.Background()) }, }) go func() { time.Sleep(5 * time.Second) log.Println(g.Done()) }() log.Println(g.Wait()) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RunnerGroup ¶
RunnerGroup is like sync.WaitGroup, the diffrence is if one task stops, all will be stopped.
func New ¶
func New() *RunnerGroup
func (*RunnerGroup) Add ¶
func (g *RunnerGroup) Add(r *Runner)
func (*RunnerGroup) Done ¶
func (g *RunnerGroup) Done() error
Call Done if you want to stop all. return the stop's return which is not nil, do not guarantee, because starts may ended caused by itself.
func (*RunnerGroup) Wait ¶
func (g *RunnerGroup) Wait() error
Call Wait after all task have been added, Return the first ended start's result.
Click to show internal directories.
Click to hide internal directories.