-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
47 lines (37 loc) · 1 KB
/
example_test.go
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
package bye_test
import (
"errors"
"fmt"
"time"
"go.szostok.io/bye"
)
func ExampleParentService() {
shutdown := bye.NewParentService(bye.WithTimeout(30 * time.Second))
shutdown.Register(bye.Func(func() {
time.Sleep(30 * time.Millisecond)
fmt.Println("Closing non error function call")
}))
shutdown.Register(bye.ErrFunc(func() error {
time.Sleep(15 * time.Millisecond)
fmt.Println("Closing error function call")
return errors.New("I don't want to quit!")
}))
shutdown.Register(&exampleService{})
fmt.Println("Shutting down the application...")
err := shutdown.Shutdown()
fmt.Println(err)
// output:
// Shutting down the application...
// Closing example Shutdownable Service
// Closing error function call
// Closing non error function call
// 1 error occurred:
// * I don't want to quit!
//
}
var _ bye.ShutdownableService = (*exampleService)(nil)
type exampleService struct{}
func (e exampleService) Shutdown() error {
fmt.Println("Closing example Shutdownable Service")
return nil
}