How about


    var tries = 20;
    var tryToUnlock = function () {
      var rv = screen.mozLockOrientation(OrientationManager.defaultOrientation);
      if (!rv && tries--) {
         setTimeout(tryToUnlock, 20);
      }
    };
    tryToUnlock();

So we could try for 20 times in 20*20=400ms. You might want to tweak these numbers though.