In other languages, I can run several tasks in concurrently and get the result of each in corresponding variable.
For example in JS:
getApi1()
.then( res => console.debug("Result 1: ", res) )
getApi2()
.then( res => console.debug("Result 2: ", res) )
getApi3()
.then( res => console.debug("Result 3: ", res) )
And I know exactly in which variable the result of the execution of which function.
The same is in Python asyncio:
task1 = asyncio.create_task(getApi1)
task2 = asyncio.create_task(getApi2)
result1 = await task1
result2 = await task2
I'm new in Go lang. All guides say to use channels with goroutines.
But I don't understand, when I read from the channel, how to be sure which message matches which result?
resultsChan := make(chan map)
go getApi1(resultsChan)
go getApi2(resultsChan)
go getApi3(resultsChan)
for {
result, ok := <- resultsChan
if ok == false {
break
} else {
// HERE
fmt.Println(result) // How to understand which message the result of what API request?
}
}