Refactor "n running scripts" code to use a channel

The idea is that this will be useful for the load balancing code.