I am building a native desktop application in javascript using CEF, And I have API to access filesystem from CEF. I have a senario, in which I need to get names of all files(there could be trees of directories) within a particular directory. I need to get result array, I am using jquery promises. What I don't understand is: when do I resolve the promise to get final result array?
/*read all directories under this and get path*/
    var result = [];
    function _processEntries(dirPath) {
        var dirEntry = new NativeFileSystem.DirectoryEntry(dirPath), deferred = new $.Deferred();
        /*async call*/
        dirEntry.createReader().readEntries(
            function (entries) {
                for (var i = 0; i < entries.length; i++) {
                    if (entries[i].isDirectory) {
                        _processEntries(entries[i].fullPath).done(function () {
                            deferred.resolve(result);
                        });
                    } else {
                        result.push(entries[i].fullPath);
                    }
                }
            },
            function (error) {
                console.log("Failed while reading dir:", error);
            }
        );
        return deferred.promise();
    }
// Calling function
_processEntries("C:/Users/abc").done(function(result){
    console.log("FILES ARRAY:",result);
});
Please suggest any other technique if I am doing it wrong :)
 
     
     
    