diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cb2e16..0aed525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/goworker.go b/goworker.go index 835cc78..4b1ca64 100644 --- a/goworker.go +++ b/goworker.go @@ -41,6 +41,8 @@ type WorkerSettings struct { UseNumber bool SkipTLSVerify bool TLSCertPath string + + closed chan struct{} } func SetSettings(settings WorkerSettings) { @@ -88,6 +90,8 @@ func Init() error { return err } + workerSettings.closed = make(chan struct{}) + initialized = true } @@ -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