use select statments when writting to channels in a for loop. adds protection against memory leaking if consumer thread dies