Add a wait function that will block until empty handler queues