3 ms·
You could also have N channels, one for each argument, and use reflect.Select to receive the results as soon as available, waiting to print any result until all
by kbolino 2y ago
You could also have N channels, one for each argument, and use reflect.Select to receive the results as soon as available, waiting to print any result until all of its predecessors have come in.
You could also have a mutex-guarded block at the end of every worker goroutine to do the printing and a sync.WaitGroup to follow the workers in main.
- yencabulator 2y agoNo need for reflect.Select, just loop through the channels and wait on each. That'll do your "predecessors" part just by the sake that it's an in-order for loop.
- kbolino 2y agoYou're right, and for some reason I thought that solution had been ruled out.