Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Signals, so closure-shared resources can be cleaned up on quit #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,25 @@
// }
//
// To create workers that share a database pool or other
// resources, use a closure to share variables.
// resources, use a closure to share variables. Clean up
// shared resources using the channel provided by the
// Signals function.
//
// package main
//
// import (
// "github.com/benmanns/goworker"
// )
//
// func newMyFunc(uri string) {
// func newMyFunc(uri string) func(string, args ...interface{}) error {
// foo := NewFoo(uri)
//
// quit := goworker.Signals()
// go func() {
// <-quit
// foo.CleanUp()
// }()
//
// return func(queue string, args ...interface{}) error {
// foo.Bar(args)
// return nil
Expand Down
2 changes: 1 addition & 1 deletion goworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Work() error {
return err
}

quit := signals()
quit := Signals()

pool := newRedisPool(uri, connections, connections, time.Minute)
defer pool.Close()
Expand Down
2 changes: 1 addition & 1 deletion signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
"syscall"
)

func signals() <-chan bool {
func Signals() <-chan bool {
quit := make(chan bool)

go func() {
Expand Down