lang: core: os: Simplify waitgroup
Doesn't need to be part of the struct. Maybe there are others like this that need porting.
This commit is contained in:
@@ -63,7 +63,6 @@ type ReadFileFunc struct {
|
||||
|
||||
recWatcher *recwatch.RecWatcher
|
||||
events chan error // internal events
|
||||
wg *sync.WaitGroup
|
||||
|
||||
input chan string // stream of inputs
|
||||
filename *string // the active filename
|
||||
@@ -106,7 +105,6 @@ func (obj *ReadFileFunc) Init(init *interfaces.Init) error {
|
||||
obj.init = init
|
||||
obj.input = make(chan string)
|
||||
obj.events = make(chan error)
|
||||
obj.wg = &sync.WaitGroup{}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -114,11 +112,12 @@ func (obj *ReadFileFunc) Init(init *interfaces.Init) error {
|
||||
func (obj *ReadFileFunc) Stream(ctx context.Context) error {
|
||||
//defer close(obj.input) // if we close, this is a race with the sender
|
||||
defer close(obj.events) // clean up for fun
|
||||
defer obj.wg.Wait()
|
||||
wg := &sync.WaitGroup{}
|
||||
defer wg.Wait()
|
||||
defer func() {
|
||||
if obj.recWatcher != nil {
|
||||
obj.recWatcher.Close() // close previous watcher
|
||||
obj.wg.Wait()
|
||||
wg.Wait()
|
||||
}
|
||||
}()
|
||||
for {
|
||||
@@ -144,7 +143,7 @@ func (obj *ReadFileFunc) Stream(ctx context.Context) error {
|
||||
|
||||
if obj.recWatcher != nil {
|
||||
obj.recWatcher.Close() // close previous watcher
|
||||
obj.wg.Wait()
|
||||
wg.Wait()
|
||||
}
|
||||
// create new watcher
|
||||
obj.recWatcher = &recwatch.RecWatcher{
|
||||
@@ -169,9 +168,9 @@ func (obj *ReadFileFunc) Stream(ctx context.Context) error {
|
||||
// watch recwatch events in a proxy goroutine, since
|
||||
// changing the recwatch object would panic the main
|
||||
// select when it's nil...
|
||||
obj.wg.Add(1)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer obj.wg.Done()
|
||||
defer wg.Done()
|
||||
for {
|
||||
var err error
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user