While loop and async function

Only by realizing that it’s not a problem at all, but rather part and parcel of how asynchronous operations work.

Read this post. You have to decide which of these three types getP() is. Judging from its name, I would guess it’s a #3, in which case it needs to return the Promise it got from try3(), and the then logic needs to be in getP()'s caller, not in getP itself.