Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use sync/atomic to keep tab on go routines (redhat-developer#5961)
* Use sync/atomic to keep tab on go routines Signed-off-by: Dharmit Shah <shahdharmit@gmail.com> As a result of the code pushed in redhat-developer#5942, `odo logs --follow` would hang if user executed it without pushing the component in either dev or deploy modes. This was not a problem before that PR was merged. This was caused because below code would not get executed in business layer if user was using follow mode: ``` if !follow { doneChan <- struct{}{} } ``` The reason we didn't execute it for follow mode was that it prematurely exited and often didn't print the logs of all the containers. This PR uses `sync/atomic` to keep a tab on go routines started for `odo logs --follow` instead of using `sync.WaitGroup`, and checks if no go routines are running before it exits. This enables us to use `doneChan <- struct{}{}` in business layer irrespective of user running `odo logs` with or without follow mode. Why not use `wg.Wait()` as first statement instead in `case <-events.Done:`? This is because `wg.Wait()` is a blocking call and won't be called upon each time a go routine for `odo logs --follow` is done (`wg.Done()`). This leads to same problem as that fixed by PR 5942, which is that `odo logs --follow` won't exit even if the underlying odo component was deleted. * Use a struct instead of int64 for atomic Signed-off-by: Dharmit Shah <shahdharmit@gmail.com> `go vet` complains about direct assignment to an atomic value. Hence, an anonymous struct to fix the problem.
- Loading branch information