GoogleChromeLabs / browser-fs-access

File System Access API with legacy fallback in the browser
https://googlechromelabs.github.io/browser-fs-access/demo/
Apache License 2.0
1.38k stars 84 forks source link

Ability to abort a `directoryOpen` #75

Closed Amatewasu closed 2 years ago

Amatewasu commented 2 years ago

When calling the function directoryOpen({ recursive: true }) and the user selects a large folder (such as C:\ for Windows users for example), it will try to load too many files and the promise will not resolve.

It would be great to add the ability to abort. I don't know what could be exactly the best parameters to add, but I can think of:

tomayac commented 2 years ago

I think a timeout would be the most logical. You can do this without any changes actually:

Promise.race([
  directoryOpen({ recursive: true }),
  sleep(2000),
]);
Amatewasu commented 2 years ago

Great idea, thank you!

Amatewasu commented 2 years ago

I identify two problems with Promise.race.

tomayac commented 2 years ago
  • it does not resolve/reject the directoryOpen promise that still runs in the background, it could be quite resource-intensive if the user selected a large folder

You could maybe make this work by leveraging the legacySetup parameter.

  • it includes the elapsed time for the user to select the folder, thereby Promise.race will resolve/reject after the sleep duration if the user takes a while to select the folder

That's true. I don't think there is a workaround unfortunately.