Call defer to close the channels just before return called in the function.