I try to build a keyword list from all existing keywords. I manage to retrieve them all and output them in the debug console.
I am confused about how and when to call resolve(taxonomyKeywords). I like to call it when all loops and their inner loops are finished. I tried using foreach, yet run in the same issue. Is my approach way off and there's a much easier way?
private searchKeyword(searchTerm: string, results: ITag[]) : ITag[] | Promise<ITag[]>
{
  return new Promise<IPersonaProps[]>( (resolve, reject) => {
    let taxonomyKeywords : ITag[] = [];
    this.props.taxonomyProvider.getTermStores().then( (stores: ITermStore[]) => {
      for(var store of stores )
      {
        this.props.taxonomyProvider.getTermGroups( store.id ).then( (groups: ITermGroup[]) => {
          for(var group of groups)
          {
            this.props.taxonomyProvider.getTermSets(group).then( (sets: ITermSet[]) => {
              for(var termSet of sets)
              {
                this.props.taxonomyProvider.getTerms(termSet).then( (terms: ITerm[]) => {
                  for(var term of terms)
                  {
                    if( term.name.indexOf(searchTerm) >= 0 )
                    {
                      taxonomyKeywords.push( { key: term.name, name: term.name} );
}}});}});}});}});});}
 
    