A
A
Andrey2016-03-29 19:44:12
go
Andrey, 2016-03-29 19:44:12

How to make multiple listeners from one channel in Golang?

I apologize if the title question confused you (I don’t know how to put it better).
What would several goroutines write to the channel and one read - it's not difficult to do https://play.golang.org/p/FBtwyIRmQl
But how to do it the other way around?
What would one (or several) goroutine write to the channel and everyone who listens to it would receive this message?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pavlyuk, 2016-03-29
@goodwin332

A message sent to a channel always reaches only one listener. In order for the message to be guaranteed to be delivered to the nth number of listeners, you will have to make an array of channels, one for each listener, or a special lone receiver that will read from the channel alone and send the message to everyone.

M
Mr4x, 2016-03-29
@Maxim_Samburskiy

I think this will help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question