RecyclerView and DiffUtil - A Concurrency Nightmare
<p><a href="https://developer.android.com/reference/android/support/v7/util/DiffUtil.html" rel="noreferrer">The documentation for <code>DiffUtil</code></a> suggests generating the <code>DiffUtil.DiffResult</code> on a background thread because of potential long calculation times. This seems like a bad idea to me, because that thread could be operating on stale data in a situation like the following (assuming <code>list</code> access is thread safe):</p>

<ol>
<li>Add data to <code>list</code> and notify adapter</li>
<li>Need to replace <code>list</code> with <code>newList</code> which would have a diff of some additions and some removals</li>
<li>Call <code>DiffUtil.calculateDiff</code> in the background and get the <code>DiffResult</code> for <code>list</code> and <code>newList</code>, and post a message to the main thread that will use <code>newList</code> and call <code>DiffResult.dispatchUpdatesTo</code></li>
<li>Before that message is handled, the user takes an action on the main thread that causes mutations to <code>list</code></li>
<li>The message is handled, <code>newList</code> is set to be the new data source and <code>DiffResult.dispatchUpdatesTo</code> is run causing an inconsistent view of the underlying data + a loss of any mutations since the <code>DiffResults</code> were calculated</li>
</ol>

<p>Well that's no good, so let's change starting from step 3:</p>

<ol start="3">
<li>Set <code>newList</code> as the new data source, call <code>DiffUtil.calculateDiff</code> in the background and get the <code>DiffResult</code> for <code>list</code> and <code>newList</code>, and post a message to the main thread that will call <code>DiffResult.dispatchUpdatesTo</code></li>
<li>Before that message is handled, the user takes an action on the main thread that causes mutations to <code>newList</code>, and notifies adapter, causing an inconsistent view of data because <code>DiffResult.dispatchUpdatesTo</code> hasn't been called yet</li>
</ol>

<p>There are more variations on this, but none are good. It seems like the only way to reliably use <code>DiffUtil</code> with a large dataset and changeset is to either disable or queue all updates until <code>DiffResult.dispatchUpdatesTo</code> is called.</p>

<p>Am I missing something that would make the above false?</p>