-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgo_group_test.go
More file actions
48 lines (39 loc) · 846 Bytes
/
go_group_test.go
File metadata and controls
48 lines (39 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package g
import (
"errors"
"fmt"
"testing"
"time"
)
func TestNewGoGroup(t *testing.T) {
// ...
c := NewGoGroup()
defer c.CallExit()
defer c.Wait()
defer c.CallQuit()
// ctx, cancel := context.WithCancel(context.Background())
// defer cancel()
// ...
c.Go(func() {
<-time.After(time.Second * 5)
c.Exit(errors.New("subjective withdrawal from the current program"))
})
c.Go(func() {
<-time.After(time.Second)
panic("test panic recover")
})
// ...
// c.Go(func() {
// notify := make(chan os.Signal, 1)
// signal.Notify(notify, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
// select {
// case <-ctx.Done():
// case sig := <-notify:
// c.Exit(errors.New(sig.String()))
// }
// })
if err := <-c.ExitErr(); err != nil {
fmt.Println("the program is about to exit -->", err.Error())
}
// ...
}