title: Using Firefox's Downloads.jsm to download file one at a time while observing them?
body: <p>Mozilla gave <a href="https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm#Observing_downloads" rel="nofollow">some sample code using Firefox's Downloads.jsm</a>, I'm trying to use Downloads.jsm to download several files one at a time in a serial fashion.</p>
  
  <p>But when I tried using it like this:</p>
  
  <pre><code>Task.spawn(function () {
  
    let list = yield Downloads.getList(Downloads.ALL);
  
    let view = {
      onDownloadAdded: download =&gt; console.log("Added", download),
      onDownloadChanged: download =&gt; console.log("Changed", download),
      onDownloadRemoved: download =&gt; console.log("Removed", download),
    };
  
    yield list.addView(view);
    try {
      let download = yield Downloads.createDownload({
        source: "http://www.mozilla.org/",
        target: OS.Path.join(OS.Constants.Path.tmpDir, "example-download.html"),
      });
      list.add(download);
      download.start();
    } finally {
      yield list.removeView(view);
  
      moveOnToNextDownload();
    }
  
  }).then(null, Components.utils.reportError);
  </code></pre>
  
  <p>where I move on to the next download using <code>moveOnToNextDownload()</code>, several downloads are started and files are downloaded in parallel. </p>
  
  <p>How should I use Downloads.jsm to download files one at a time in a serial fashion?</p>