I\'m whiting firefox extension. I got function that\'s reading contents of file:
var HelloWorld = {...
getData: function () {
var env = Components.classe
how to fix it
Don't use the outer alert.
That's how asynchronous code works, you can only access the data in the callbacks that are executed later. However, with promise chaining, it doesn't need to go all in the same callback or in nested callbacks.
let decoder = new TextDecoder();
let promise = OS.File.read(path);
return promise.then(function onSuccess(array) {
var line = decoder.decode(array);
alert(line);
return line;
}).then(function onSuccess2(line) {
alert("ducky:"+line+"duck");
return line;
}); // return the promise for the line!