Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions internal/exercises/catalog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,11 @@ projects:
- "Use Go's `time.Unix()` to convert an epoch to time."
- "Use `t.Unix()` to convert time back to epoch."
- "Remember Go’s `time.Parse` can help parse date strings."

- slug: 37_waitGroup
title: "WaitGroups"
difficulty: beginner
topics: ["waitGroup", "go"]
hints:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Place “WaitGroups” under concepts, not projects (issue #67 says Concept).

Move this entry to the concepts section to match the issue’s acceptance criteria.

🤖 Prompt for AI Agents
In internal/exercises/catalog.yaml around lines 205 to 209, the "WaitGroups"
exercise is currently listed under projects but should be placed under the
concepts section per issue #67; move the entire exercise entry (slug, title,
difficulty, topics, hints) from the projects list into the concepts list,
preserving its fields and indentation to match surrounding YAML entries, and
remove the original entry from the projects section so there are no duplicates.

- "Use Go's waitGroups inorder to wait for the goroutines"

23 changes: 23 additions & 0 deletions internal/exercises/solutions/37_waitGroup/waitGroup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package waitgroup

import (
"sync"
)

// TODO: Implement these functions so tests pass

// The waitGroup in Go is used to wait for a collection of goroutines to finish executing

func worker(wg *sync.WaitGroup, result *string) {
defer wg.Done()
*result = "Worker done"
}

func waitGroup() string {
var wg sync.WaitGroup
result := ""
wg.Add(1)
go worker(&wg, &result)
wg.Wait()
return result
}
18 changes: 18 additions & 0 deletions internal/exercises/templates/37_waitGroup/waitGroup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package waitgroup

import (
"sync"
)

// TODO: Implement these functions so tests pass

func worker(wg *sync.WaitGroup, result *string) {
*result = "Worker done"
}

func waitGroup() string {
var wg sync.WaitGroup
result := ""
go worker(&wg, &result)
return result
}
11 changes: 11 additions & 0 deletions internal/exercises/templates/37_waitGroup/waitGroup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package waitgroup

import "testing"

func TestHello(t *testing.T) {
got := waitGroup()
want := "Worker done"
if got != want {
t.Fatalf("waitGroup() = %q, want %q", got, want)
}
}