From 11a32ca219905f7c42698b55b6af9920626b7b51 Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Thu, 17 Jan 2019 07:57:51 +0300 Subject: [PATCH] Remove context from constructor --- README.md | 2 +- example/http_server.go | 5 +++-- rutina.go | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2034fe6..0733929 100755 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ HTTP server with graceful shutdown (`example/http_server.go`): ``` // New instance with builtin context. Alternative: r, ctx := rutina.WithContext(ctx) -r, _ := rutina.New(rutina.WithStdLogger()) +r := rutina.New(rutina.WithStdLogger()) srv := &http.Server{Addr: ":8080"} http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { diff --git a/example/http_server.go b/example/http_server.go index ef25567..86255e6 100755 --- a/example/http_server.go +++ b/example/http_server.go @@ -4,15 +4,16 @@ package main import ( "context" - "github.com/neonxp/rutina" "io" "log" "net/http" + + "github.com/neonxp/rutina" ) func main() { // New instance with builtin context. Alternative: r, ctx := rutina.OptionContext(ctx) - r, _ := rutina.New(rutina.WithStdLogger()) + r := rutina.New(rutina.WithStdLogger()) srv := &http.Server{Addr: ":8080"} http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { diff --git a/rutina.go b/rutina.go index 2a28682..8a8cccc 100755 --- a/rutina.go +++ b/rutina.go @@ -22,11 +22,11 @@ type Rutina struct { } // New instance with builtin context -func New(opts ...Option) (*Rutina, context.Context) { +func New(opts ...Option) *Rutina { ctx, cancel := context.WithCancel(context.Background()) var counter uint64 = 0 r := &Rutina{ctx: ctx, Cancel: cancel, counter: &counter, cancelByError: false} - return r.WithOptions(opts...), ctx + return r.WithOptions(opts...) } func (r *Rutina) WithOptions(opts ...Option) *Rutina {