diff options
author | Alexander Kiryukhin <a.kiryukhin@corp.mail.ru> | 2019-01-11 17:22:06 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@corp.mail.ru> | 2019-01-11 17:22:06 +0300 |
commit | a4e62510cf1c06831c9c6e4c3a21ff986ebad14c (patch) | |
tree | 80ca7af46604e47f4833a4466e9ca9d7e82ad17b /README.md | |
parent | c582001e89c0b81df1b9eb1e8f1857d1c075a805 (diff) |
Added OS signals handler
Added go.mod
Diffstat (limited to 'README.md')
-rwxr-xr-x | README.md | 15 |
1 files changed, 3 insertions, 12 deletions
@@ -15,7 +15,7 @@ HTTP server with graceful shutdown (`example/http_server.go`): ``` // New instance with builtin context. Alternative: r, ctx := rutina.WithContext(ctx) -r := rutina.New() +r, _ := rutina.New() srv := &http.Server{Addr: ":8080"} http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -38,17 +38,8 @@ r.Go(func(ctx context.Context) error { return srv.Shutdown(ctx) }) -// OS signals subscriber -r.Go(func(ctx context.Context) error { - sig := make(chan os.Signal, 1) - signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT) - select { - case <-sig: - log.Println("TERM or INT signal received") - case <-ctx.Done(): - } - return nil -}) +// OS signals listener +r.ListenTermSignals() if err := r.Wait(); err != nil { log.Fatal(err) |