tests/runonce/main.go

45 lines
689 B
Go

package main
import (
"fmt"
"log"
"runonce/cleaner"
"sync"
)
type srv struct {
id int
msg string
}
func main() {
wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
ii := i
wg.Add(1)
go func() {
s := srv{id: ii, msg: fmt.Sprintf("handler number %d\n", ii)}
fmt.Printf("handler %d return %#v\n", ii, s.handle())
wg.Done()
fmt.Printf("goroutine %d exit\n", ii)
}()
}
wg.Wait()
fmt.Println("Game over")
}
func (s srv) handle() bool {
fmt.Printf("run handle number %d\n", s.id)
wg := sync.WaitGroup{}
go func() {
wg.Add(1)
if err := cleaner.GetInstance().Clean(s.id); err != nil {
log.Fatal("sdfdssd")
}
wg.Done()
}()
wg.Wait()
return true
}