Skip to content

parallel-letter-frequency: false positive on 'wait for goroutines' #74

@bitfield

Description

@bitfield

Solution 7ae34b6188784d06a7fd50faa6872bba is fine:

func ConcurrentFrequency(strings []string) FreqMap {
	results := make(chan FreqMap)
	m := FreqMap{}
	for _, currentString := range strings {
		go func(text string) {
			results <- Frequency(text)
		}(currentString)
	}
	for range strings {
		for k, v := range <-results {
			m[k] += v
		}
	}
	return m
}

but Exalysis thinks it's waiting for the goroutines to be done [most definitely my fault]:

Here is one thought for further improvement:
- It looks like you wait until all results have been received from the goroutines before starting to merge them. In fact, you can (and should) start processing as soon as you receive the first result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions