handle graceful shutdown when dequeue operation is repetitive within for
loop