How to wrap function call that sometimes does async call to make it behave synchronously
<p>I have a function which logic is:</p>

<pre><code>    _setDataChunk: function (action) {
        var self = this;
        /* some code */
        var data = self._getDataChunk(action);
        populateWidget(data);
    }
</code></pre>

<p><code>GetDataChunk</code> sometimes has an AJAX call inside, sometimes not. How to wrap <code>_getDtaChunk</code> function to force it act synchronously all the time?</p>