Use a Producer-Consumer pattern