Tengo una función que se ve así:
async handleFile(e){ var file = e.target.files[0]; var reader = new FileReader(); reader.onload = async function(f){ await somelibrary.load(f.target.result) await somelibrary.render() await someotherlibrary.init() } await reader.readAsText(file); }Necesito saber si la carga y el procesamiento han funcionado, al menos si no han lanzado una excepción. Así que mi idea era hacer algo como esto:
async handleFile(e){ var file = e.target.files[0]; var reader = new FileReader(); reader.onload = async function(f){ try { await somelibrary.load(f.target.result) await somelibrary.render() await someotherlibrary.init() return true } catch (e) { console.log(e); return false } } var rendered = await reader.readAsText(file); console.log(rendered) }Pero esto solo registra undefined. Entiendo por qué, mi función solo espera la parte de lectura y no el manejo real del contenido en .onload... Pero, ¿cómo hago esto correctamente?