jsmediatags icon indicating copy to clipboard operation
jsmediatags copied to clipboard

Make Reader Cancelable/Abortable

Open toastal opened this issue 3 years ago • 2 comments

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().

toastal avatar Jul 05 '20 11:07 toastal

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

aadsm avatar Mar 01 '21 03:03 aadsm

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.

toastal avatar Mar 01 '21 10:03 toastal