Im trying to use the new HTML5 FileSystem API for creating/adding/deleting files with javascript. (for use with a self-service cash desk)
current code:
var entries;
function onInitFs(fs) {
fileSystem = fs;
debug('Opened file system: ' + fs.name);
loadFilelist();
// The functions below execute before loadFilelist() is ready!
setFileList(entries);
showFilenames(entries);
}
function loadFilelist() {
entries = [];
var dirReader = fileSystem.root.createReader();
readEntries();
function readEntries() {
dirReader.readEntries(function(results) {
if (results.length > 0) {
debug(results.length + " Files added to the filesystemFilelist");
entries = entries.concat(toArray(results));
entries.sort();
readEntries();
}else{
debug(entries.length + " Files in the filesystemFilelist");
//done
}
}, fileErrorHandler);
};
}
/* For putting debug text in the debug screen (in this case its the console) */
function debug(content) {
window.console.log(content);
}
The problem with this is that the function dirReader.readEntries(function (), callback) waits for a callback. Meanwhile the code that comes next already executes.
Ive looked it up in the File API and it seems the function only works with a callback
How can i prevent that the function calls
setFileList(entries);
showFilenames(entries);
execute before loadFilelist is done?
Thanks in advance
Currently im using a worker to do the synchronous work! Works perfect! I made a ‘command system thingy’ between the main and the worker scripts. I will post the basics if someone is interested! Barely anybody looked at this question so for now i only mark it as SOLVED