aadsm / jsmediatags

Media Tags Reader (ID3, MP4, FLAC)
Other
745 stars 128 forks source link

Make Reader Cancelable/Abortable #131

Open toastal opened 4 years ago

toastal commented 4 years ago

Given Reader.read() is an asynchronous effect, it should be able to be canceled. The native FileReader has an abort() method, however this is not directly exposed.

Luckily JavaScript doesn't have a private methods/encapsulation; I've not tested yet, but I'll try Reader._getFileReader().abort().

aadsm commented 3 years ago

That's going to be tricky because not all file readers will allow cancelling so can't put it as the generic interface.

toastal commented 3 years ago

tryAbort() that catches the uncancelable effect as a success? Or expose it and let the user do the catching? This library API is currently lacking without cancel/abort as it doesn't fit a Future or Aff (or other names) interface for asynchronous effects. Fluture is one JavaScript implementation of said specs.

This has been one of the criticisms of the Promise API and AbortControllers have been bolted on to deal with this issue in hindsight. It helps consumers when APIs are fleshed out with the ability to abort/cancel an asynchronous task.