samedi 19 septembre 2020

How to implement a channel and multiple readers that read the same data at the same time?

I need several functions to have the same channel as a parameter and take the same data, simultaneously. Each of these functions has an independent task from each other, but they start from the same value.

For example, given a slice of integers, one function calculates the sum of its values ​​and another calculates the average, at the same time. They would be goroutines.

One solution would be to create multiple channels from one value, but I want to avoid that. I might have to add or remove functions and for this, I would have to add or remove channels.

I think I understand that the Fan Out pattern could be an option, but I can't quite understand its implementation.

Aucun commentaire:

Enregistrer un commentaire