var reader = new FileReader(),
file1 = new Blob(['Hola'],{type : 'text/plain'}),
file2 = new Blob(['Mundo'],{type : 'text/plain'}),
result = null;
reader.addEventListener('load',function(event){
result = this.result;
});
reader.readAsText(file1);
var interval = setInterval(function(){
if(reader.readyState === 2){
clearInterval(interval);
reader.readAsText(file2);
}
},100);
Suppose I need to read 2 files sequentially with the same FileReader instance, so to avoid getting an error "DOMException: Failed to execute 'readAsText' on 'FileReader': The object is already busy reading Blobs. " so what I do is use a setInterval and it is checking every 100 milliseconds if the readyState reader property is equal to 2 (DONE) and then there if you read the other file .
However I would like to know how I can achieve something similar using promises since I tried it and the truth is that I could not get the fact of reading a file, wait for it to end and then there if start reading another with the same instance of FileReader (I really do not care if it is worse to try to do it synchronously I just want to know how to do this using promises and if I can somehow replace the "listeners" (load, loadstart, progress, loadend etc ...) by promises)