title: Convert async function to RxJs Observable
body: <p>To prevent writing a certain amount of code, such as this example:</p>
  <pre class="lang-js prettyprint-override"><code>    ...
      public getDataSet() : Observable&lt;any&gt;
      {
          return new Observable(observer =&gt; {
              if (this.dataset === undefined) {
                  this.get().subscribe(data =&gt; {
                      this.dataset = new DataSet(data) ;
                      observer.next(this.dataset)
                      observer.complete() ;
                  }) ;
              }
              else {
                  observer.next(this.dataset)
                  observer.complete() ;
              }
          }) ;
      }
  </code></pre>
  <p>I would like to use <em>async/await</em> feature but still return an Observable to remain consistent in using asynchronous data gathering services.</p>
  <p>Thus according to RxJs's documentation, I should be using <code>from()</code> operator.
  <a href="https://www.learnrxjs.io/learn-rxjs/operators/creation/from" rel="nofollow noreferrer">https://www.learnrxjs.io/learn-rxjs/operators/creation/from</a></p>
  <p>Here is what I try to implement (which looks much more concise) :</p>
  <pre class="lang-js prettyprint-override"><code>import { Observable, from } from 'rxjs' ;
  ...
          return from(async () =&gt; { // ✘ error
              if (this.dataset === undefined) this.dataset = new DataSet(await this.get().toPromise()) ;
              return this.dataset ;
          }) ;
  </code></pre>
  <p>However, TypeScript doesn't recognize <code>async () =&gt; {}</code> as an <code>ObservableInput</code>, but it does recognize this one :</p>
  <pre class="lang-js prettyprint-override"><code>import { Observable, from } from 'rxjs' ;
  ...
          return from(new Promise((resolve) =&gt; { // ✔ valid
              if (this.dataset === undefined) {
                  this.get().toPromise().then(data =&gt; {
                      this.dataset = new DataSet(data) ;
                      resolve(this.dataset) ;
                  }) ;
              }
              else resolve(this.dataset) ;
          })) ;
  </code></pre>
  <p>Though, JavaScript's <code>async</code> keyword makes a function always return a Promise.</p>
  <pre class="lang-js prettyprint-override"><code>console.log((async () =&gt; {}) ())
  // Promise {}
  </code></pre>
  <p>Is there a way to make the <code>from()</code> RxJs operator accepting async promises ?</p>