https://github.com/peteryangs/waittree
https://github.com/peteryangs/waittree
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/peteryangs/waittree
- Owner: PeterYangs
- Created: 2021-12-25T14:50:38.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-10T05:47:41.000Z (over 4 years ago)
- Last Synced: 2024-06-20T10:05:03.419Z (about 2 years ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
```go
package main
import (
"fmt"
"github.com/PeterYangs/waitTree"
"time"
)
func main() {
father := waitTree.NewWaitTree(waitTree.Background())
son := waitTree.NewWaitTree(father)
son2 := waitTree.NewWaitTree(father)
for i := 0; i < 10; i++ {
son.Add(1)
go func() {
defer func() {
son.Done()
//从父类中释放
son.Release()
}()
time.Sleep(1 * time.Second)
fmt.Println("son done")
}()
}
for i := 0; i < 10; i++ {
son2.Add(1)
go func() {
defer func() {
son2.Done()
//从父类中释放
son2.Release()
}()
time.Sleep(2 * time.Second)
fmt.Println("son2 done")
}()
}
father.Wait()
father.Wait()
//释放所有子wait
//father.ReleaseSon()
}
```