Help with serial communication

Not an Arduino developer, but if I’m understanding your issue here…

The key thing is that Processing event handling happens each time draw() returns. draw() is your “while” loop. So take the things that you would put in a while, and put them in draw(). This will process commands at your frameRate() fps (e.g. 60/second). When nothing is available, it will keep looping. Your sketch will also stay responsive the whole time.

void draw() {
  if(myPort.available()!=0) sendNextCommand();
}

EDIT and/or, put your handing in the (library) event callback – and draw, which is your loop, will repeatedly call that handling.