add wait() method that waits until the queue is empty