Wait for the execution of an async method to return
<p>I have a callback when a file is sent for upload, where I need to return <code>false</code> if I want to prevent the upload. I want to abort when the image size is not appropriate :</p>

<pre><code>onSend = function(data)
{
    $.when(self._readImage(data[0])).then(function(img)
    {
        if (img.width &gt; 42)
        {
            // onSend should return false
        }
    });

    return true; // true == start uploading
}
</code></pre>

<p><strong>How can wait for <code>_readImage()</code> to execute before returning from <code>onSend()</code> ?</strong></p>

<p>note : <code>_readImage()</code> basically just does a <code>readAsDataURL()</code> with a deferred that is resolved in <code>img.onload()</code></p>
