Remove context from constructor

This commit is contained in:
Alexander Kiryukhin 2019-01-17 07:57:51 +03:00
parent c5776ba6a3
commit 11a32ca219
No known key found for this signature in database
GPG key ID: 5579837FDBF65965
3 changed files with 6 additions and 5 deletions

View file

@ -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) {

View file

@ -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) {

View file

@ -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 {