Recursive Promises?
You're returning the array before you populate it.
Instead, you need to return $q.all(promises)
within the then()
callback, and return the outer promise:
return fileSystem.getFolderContents(path).then(function(entries) { return $q.all(entries.map(function(e) { if (e.isFile) { // Do something return null; // Don't wait for anything } else { // Do something return walkDirectory(e.fullPath); } }));});