diff options
author | Valery Piashchynski <[email protected]> | 2021-08-28 02:03:54 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-08-28 02:03:54 +0300 |
commit | fb356081dcaea81952e2019502c0216af7d10c7d (patch) | |
tree | 45285a8541d78216983fbc4ebf89251d0777ff50 /pkg/worker_watcher | |
parent | efb3efa98c8555815330274f0618bfc080f4c65c (diff) |
Reduce error check operations
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'pkg/worker_watcher')
-rwxr-xr-x | pkg/worker_watcher/worker_watcher.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/pkg/worker_watcher/worker_watcher.go b/pkg/worker_watcher/worker_watcher.go index bdd91423..8ab9f664 100755 --- a/pkg/worker_watcher/worker_watcher.go +++ b/pkg/worker_watcher/worker_watcher.go @@ -77,11 +77,11 @@ func (ww *workerWatcher) Take(ctx context.Context) (worker.BaseProcess, error) { // thread safe operation w, err := ww.container.Pop(ctx) - if errors.Is(errors.WatcherStopped, err) { - return nil, errors.E(op, errors.WatcherStopped) - } - if err != nil { + if errors.Is(errors.WatcherStopped, err) { + return nil, errors.E(op, errors.WatcherStopped) + } + return nil, errors.E(op, err) } @@ -97,9 +97,11 @@ func (ww *workerWatcher) Take(ctx context.Context) (worker.BaseProcess, error) { // try to continuously get free one for { w, err = ww.container.Pop(ctx) - - if errors.Is(errors.WatcherStopped, err) { - return nil, errors.E(op, errors.WatcherStopped) + if err != nil { + if errors.Is(errors.WatcherStopped, err) { + return nil, errors.E(op, errors.WatcherStopped) + } + return nil, errors.E(op, err) } if err != nil { @@ -237,11 +239,8 @@ func (ww *workerWatcher) Destroy(_ context.Context) { ww.Unlock() continue } - ww.Unlock() - // unnecessary mutex, but - // just to make sure. All container at this moment are in the container + // All container at this moment are in the container // Pop operation is blocked, push can't be done, since it's not possible to pop - ww.Lock() for i := 0; i < len(ww.workers); i++ { ww.workers[i].State().Set(worker.StateDestroyed) // kill the worker |