by jarek-foksa · 12y ago · 0 comments
In the following code, assuming that there are no read errors, is the load callback guaranteed to be always executed? I.e. are DOM events dispatched only after the call stack is cleared?
let main = () => {
let reader = new FileReader();
reader.readAsText(file);
reader.addEventListener("load", callback = (event) => console.log(event.target.result));
};My _guess_ would be yes, this would work. Regardless of how fast the file loaded. One way to test it would be to stick a large while loop between readastext and addeventlistener to block the stack for a few seconds and guarantee that the file is read before the handler is bound.
I'll try and take a look when I am back at a computer if nobody else responds either way :)