function to flush queue