Mehran
Jul 9, 2023

--

Thanks for the comment, here we are using single thread but to improve the code we could create a new goroutine for each send operation, which would mean that even if one broker isn't ready to receive, the other brokers would still get their notifications.

// UpdatePrice updates the stock price and notifies all brokers

func (s *Stock) UpdatePrice(price float64) {

s.price = price

var wg sync.WaitGroup

wg.Add(len(s.brokers))

for _, broker := range s.brokers {

go func(b chan float64) {

defer wg.Done()

b <- s.price // send the updated price to the broker

}(broker)

}

wg.Wait()

}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Mehran
Mehran

Written by Mehran

Tech Team Lead | Cloud, Video & Microservices Expert | Insights on streaming innovations & programming. #ContinuousLearning

No responses yet

Write a response