I want to retrieve a list of all my MP3 files and return the list only when searching is complete, I use this code but it does not work as I expect:
(it runs on NativeScript)
const fs = require("tns-core-modules/file-system");
const root = android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();
let retrievedData = [];
export async function fileRetriever( mode , path=root ) {
    retrievedData = [];
    console.log('start');
    if ( mode == 'songs' ) retrievedData = await songSeeker();
    console.log('should be received');
    console.log(retrievedData);
    console.log('stop');
    return retrievedData;
}
function songSeeker ( path = root ) {
    let documents = fs.Folder.fromPath( path );
    documents.getEntities()
    .then( ( entities ) => {
        entities.forEach( ( entity ) => {
            // ------ catch on Folder
            if ( fs.Folder.exists( entity.path ) ) {
                songSeeker ( entity.path );
            // ------ catch on File
            } else if ( entity.extension == '.mp3' )  {
                let tmpData = { 
                    title: entity.name , 
                    path: entity.path 
                };
                retrievedData.push( tmpData );
            }
        } );
    } ).catch( ( err ) => {
        console.log(err.stack);
    } );
    return retrievedData;
}
I expect to get the complete list, but it returns just the first file!
the result is:
JS: 'start'
JS: 'should be received'
JS: [ { title: 'Hatef music.mp3',
JS:     path: '/storage/emulated/0/Hatef music.mp3' },
JS:   [length]: 1 ]
JS: 'stop'