Reading files using File Reader is asynchronous. Put your logic in the onload function to read files.
function doStuff(range, file) { var fr = new FileReader(); fr.onload = function (e) { var out = "stuff happens here"; hash = asmCrypto.SHA256.hex(out); }; fr.readAsArrayBuffer(file); }
You can even pass a callback function that will be executed after reading the file.
function doStuff(range, file, callback) { var fr = new FileReader(); fr.onload = function (e) { var out = "stuff happens here"; hash = asmCrypto.SHA256.hex(out); callback(hash); }; fr.readAsArrayBuffer(file); }
source share