Returning from a function once an async operation is done : <p>I am trying to make use an existing class which returns the data in the form of callback. The call is like this-</p>

<pre><code>class Validator{
  validate(){
     DataProvider.getInstance(new DataListener(){
       @Override
       void onDataReady(String data){
          //Do something with data
       }
   });
  }

return //data when the above call is finished
}
</code></pre>

<p>I want a clean way to return the data which should be returned when the async call is completed. Putting a while loop and checking for data is an obvious but un-clean way. Can I achieve this using RxJava?</p>

<p>Note: It's ok for the validate function to wait if the call takes time</p>
