How do I make this angular2 service somewhat synchronous?
<p>I have an angular2 service and I want it to do the following:</p>

<ol>
<li>Ftp to remote server</li>
<li>Find a file read some lines from it</li>
<li>Build a 'results' json object and return to the calling component</li>
</ol>

<p>So - actually I have steps 1 / 2 working - but of course its all 'async'. So what is happening is in my component I am doing this call to the service where <code>this.ftp</code> is the instance of my service:</p>

<pre><code> this.servers = this.ftp.lookForServers();
</code></pre>

<p>Now this correctly calls the lookForServers method of my FTP service , which looks like this:</p>

<pre><code>lookForServers(){
    var servers = [];
    var whereAreWe = 0;
    var possibles = ["/path/to/servers/"];
    for(var i=0;i&lt;possibles.length;i++){
      whereAreWe = i;
      this.c.list(possibles[i],false,(err,list)=&gt;{
        for(var p=0;p&lt;list.length;p++){
          console.log(list[p]);
          var server_version = this.grabLog(possibles[whereAreWe]+list[p].name);
          servers.push({
            name: list[p].name,
            path: possibles[whereAreWe]+list[p].name,
            version: server_version
          });
        }
      });
    }
    return servers;
   }
</code></pre>

<p>Now - the <code>this.grabLog(possibles[whereAreWe]+list[p].name);</code> function call ends up making further calls to the this.c - the FTP client, which of course is async, so this method returns almost immediately - whilst the callbacks continue to run. Those callbacks download a file, and then another callback function processes this file - again line by line, asynchronously picking out various details i want to store.</p>

<p>By the end of this chain - I have all my details in the final :</p>

<pre><code>lineReader.on('close', () =&gt; { function - but of course my `this.ftp.lookForServers();` function call has long gone....and the component is none the wiser.
</code></pre>

<p>So how can I let this work happen asynchronously, and still pass back to the component my results JSON object once the work is complete? This is probably quite a simple question about how do I make a service call a component callback...?</p>