Skip to content

Commit

Permalink
Learning Golang: Pub/Sub Concurrency Pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioCarrion committed Nov 6, 2023
1 parent 30565d9 commit ce3a09d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions 2023/concurrency-pattern-publisher-subscriber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ func main() {

s1 := ps.Subscribe()

wg.Add(1)

go func() {
wg.Add(1)
defer wg.Done()

for {
select {
case val, ok := <-s1:
if !ok {
fmt.Print("sub 1, exiting\n")
wg.Done()
return
}

Expand All @@ -90,15 +91,15 @@ func main() {

s2 := ps.Subscribe()

wg.Add(1)

go func() {
wg.Add(1)
defer wg.Done()

for val := range s2 {
fmt.Println("sub 2, value ", val)
}

wg.Done()

fmt.Print("sub 2, exiting\n")
}()

Expand Down

0 comments on commit ce3a09d

Please sign in to comment.