Okay, actually, I solved this in a different way, which is to implement my own queue that still supports push, shift, length, etc.