Skip to content

Commit

Permalink
Merge pull request #6 from cycloidio/fg-closed
Browse files Browse the repository at this point in the history
 goworker: Added a function 'Closed()' that will return when the process fully closed
  • Loading branch information
xescugc authored Jun 11, 2021
2 parents d4866ce + 6739e0f commit f4497af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## [Unreleased]

### Added

- Closed function to be able to wait for the workers to fully finish
([PR #6](https://github.com/cycloidio/goworker/issues/6))

## [0.1.7] _2021-06-09_

### Fixed
Expand Down
12 changes: 12 additions & 0 deletions goworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type WorkerSettings struct {
UseNumber bool
SkipTLSVerify bool
TLSCertPath string

closed chan struct{}
}

func SetSettings(settings WorkerSettings) {
Expand Down Expand Up @@ -88,6 +90,8 @@ func Init() error {
return err
}

workerSettings.closed = make(chan struct{})

initialized = true
}

Expand Down Expand Up @@ -123,11 +127,19 @@ func Close() error {
return err
}
initialized = false
close(workerSettings.closed)
}

return nil
}

// Closed will return a channel that will be
// closed once the full process is done closing
// and cleaning all the workers
func Closed() <-chan struct{} {
return workerSettings.closed
}

// Work starts the goworker process. Check for errors in
// the return value. Work will take over the Go executable
// and will run until a QUIT, INT, or TERM signal is
Expand Down

0 comments on commit f4497af

Please sign in to comment.