Batchplay is canceled when document.saveAs or fs.getFileForOpening

Sorry, I was mixing things

My code was redundant, I improve it but I had the same problem

export const batchPlay = async (object) => {
  let response;
  await core.executeAsModal(async () => {
      response = await action.batchPlay([object], {});
  });
  return response[0];
};

I am doing several calls at the same time to batchPlay and sometimes returns empty value, but I fixed it with a semaphore

My second problem is that saveAs sometimes works, sometimes no, how I have to save a copy from activeDocument?

I see this but it doesn’t work for me: Saving a JPG to a selected folder - #5 by 4t0m1c

It returns

Event: saveDocumentSelection may modify the state of Photoshop. Such events are only allowed from inside a modal scope. See https://www.adobe.com/go/ps_executeasmodal for details.

What I have to do?