Skip to content

RunnerGroup is like sync.WaitGroup, the diffrence is if one task stops, all will be stopped.

License

Notifications You must be signed in to change notification settings

txthinking/runnergroup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RunnerGroup

GoDoc License: MIT

RunnerGroup is like sync.WaitGroup, the diffrence is if one task stops, all will be stopped.

❤️ A project by txthinking.com

Install

$ go get github.com/txthinking/runnergroup

Example

import (
	"context"
	"log"
	"net/http"
	"time"

	"github.com/txthinking/runnergroup"
)

func Example() {
	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:
}

License

Licensed under The MIT License

About

RunnerGroup is like sync.WaitGroup, the diffrence is if one task stops, all will be stopped.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages