Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get memeories async #209

Merged
merged 4 commits into from
Oct 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions redfish/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,19 +405,20 @@ func GetMemory(c common.Client, uri string) (*Memory, error) {

// ListReferencedMemorys gets the collection of Memory from
// a provided reference.
func ListReferencedMemorys(c common.Client, link string) ([]*Memory, error) {
func ListReferencedMemorys(c common.Client, collectionLink string) ([]*Memory, error) {
var result []*Memory
if link == "" {
if collectionLink == "" {
return result, nil
}

links, err := common.GetCollection(c, link)
links, err := common.GetCollection(c, collectionLink)
if err != nil {
return result, err
}

type GetMemoryResult struct {
Item *Memory
Link string
Error error
}

Expand All @@ -426,10 +427,11 @@ func ListReferencedMemorys(c common.Client, link string) ([]*Memory, error) {

collectionError := common.NewCollectionError()
for _, memoryLink := range links.ItemLinks {
wg.Add(1)
go func(link string) {
defer wg.Done()
memory, err := GetMemory(c, link)
ch <- GetMemoryResult{Item: memory, Error: err}
ch <- GetMemoryResult{Item: memory, Link: link, Error: err}
}(memoryLink)
}

Expand All @@ -440,7 +442,7 @@ func ListReferencedMemorys(c common.Client, link string) ([]*Memory, error) {

for r := range ch {
if r.Error != nil {
collectionError.Failures[link] = r.Error
collectionError.Failures[r.Link] = r.Error
} else {
result = append(result, r.Item)
}
Expand Down