I was wondering if channels created in a for loop can be interchangeably used by subroutines running concurrently from that for loop?
Pseudo-code bellow:
for i := range Map {
channel := make(chan my_type, buff_size)
go subroutine(Map[i], channel)
}
func subroutine(name valueType, channel channelType) {
//stuff here
}
Is there a way were subroutine(Map[0]) for example, could access another channel created during another iteration of the forloop ie channel of subroutine(Map[1])?
CONTEXT: I'm currently working on a project where I have to simulate different populations of cells. Each cell has the ability to divide/differentiate/etc. To replicate the real system, the different populations have to run concurrently with one another. The issue is that I have to insert/remove a cell of a specific population type while working on a different population, this is where the channels come into play. I was thinking of running the populations concurrently each of them having an associated channel. And this is why i'm asking if we can use channels created in different for loop iterations.
I'm hoping people understand what i'm asking.
Thanks!
EDIT: I've decided to add some of my code to support my CONTEXT description with comments explaining the different elements. I've included channels but I have no idea if it works. I'm hoping it helps with understanding what I'm trying to do :
func main() {
//where envMap is a map[int]Population and Population is a struct
envMap := initialiseEnvironment(envSetupInfo)
//general simulation loop
for i := 0; i < 10; i++ {
//loop to go through all envMap elements in parallel
for eachKey := range envMap {
channel := make(chan type)
go simulateEnv(envMap[eachKey])
}
}
}
func simulateEnv(cellPopulation Population, channel chan) {
//each Population has a map[int]Cell where Cell is a struct with cell properties
cellMap := cellPopulation.cellMap
for eachCell := range cellMap {
go divisionTransition(eachCell, channel)
}
}