chore(poller): Add poller package

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2022-08-14 10:34:19 +08:00
committed by Jason Song
parent 4d7ef95d40
commit 0b885c5e5f
5 changed files with 107 additions and 2 deletions

24
poller/thread.go Normal file
View File

@ -0,0 +1,24 @@
package poller
import "sync"
type routineGroup struct {
waitGroup sync.WaitGroup
}
func newRoutineGroup() *routineGroup {
return new(routineGroup)
}
func (g *routineGroup) Run(fn func()) {
g.waitGroup.Add(1)
go func() {
defer g.waitGroup.Done()
fn()
}()
}
func (g *routineGroup) Wait() {
g.waitGroup.Wait()
}