title: How can I wrap an async function with an Observable
body: <p>I have an async function that currently looks something like this</p>
  
  <pre><code>func startLoginFlow() {
      IdentityProvider.shared.login { success, error in
          // on success a user has completed authentication
          if success {
              delegate?.userIsAuthenticated()
          }
  
  
          // on error something wen't wrong
          ....
      }
  }
  </code></pre>
  
  <p>Essentially on success a delegate method is called and some action takes place as a result.</p>
  
  <p>I'd like to wrap this as an observable instead. I do not have the option refactoring <code>IdentityProvider.shared.login</code>.</p>
  
  <p>I essentially just need the observable to emit so I can subscribe and take action elsewhere using <code>onNext</code>.</p>
  
  <p>I am currently doing the following</p>
  
  <pre><code>  func startLoginFlow() -&gt; Observable&lt;Void&gt; {
          return Observable.create { [weak self] observable in
              IdentityProvider.shared.login { success, error in
                  if success {
                      observable.onNext(Void())
                  }
              }
              return Disposables.create()
          }
      }
  </code></pre>
  
  <p>Is this the best way to do this? I wasn't sure if I should use <code>Observable.of</code> and subscribe to the result of  <code>IdentityProvider.shared.login</code></p>