Open toastal opened 4 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.
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 AbortController
s 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.
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()
.