How do I convert Q.defer() to Promise for instance variables?
<p>I am currently looking to convert a library that uses Q.defer() for promise handling to use ES6 Promises. I understand the basics on how to convert Q.defer() to Promise, but every example I have ran into does not talk about the structure that I am running into where I need to convert class instance variables away from Q.defer() to Promises that do NOT resolve immediately. For example, take the following code.</p>

<pre><code>import 'Q' from 'q';
class Service {
  constructor() {
    this.items = Q.defer();

    // This would then make a call to some backend service... setTimeout to simulate.
    setTimeout(() =&gt; {
      this.items.resolve(['one', 'two', 'three']);
    }, 1000);
  }
  getItems() {
    return this.items.promise;
  }
}
</code></pre>

<p>I would like to use this class like the following.</p>

<pre><code>let service = new Service();
service.getItems().then((items) =&gt; {
  console.log(items);
});
</code></pre>

<p>Currently, I am reading that you should use Promise.resolve() to create a similar structure, however, if I replace Q.defer() with Promise.resolve(), the promise resolves immediately with no items, which is not what I am wanting. Here is what I was thinking could be the replacement.</p>

<pre><code>class Service {
  constructor() {
    this.items = Promise.resolve();

    // This would then make a call to some backend service... setTimeout to simulate.
    setTimeout(() =&gt; {
      this.items.then(() =&gt; {
        return ['one', 'two', 'three'];
      });
    }, 1000);
  }
  getItems() {
    return this.items;
  }
}
</code></pre>

<p>This doesn't work since the promise resolves immediately...</p>

<p>How do I convert the code above to use Promises?</p>