Async/Await and MainActor Strategies
<p>Pretty much every article that discusses Swift async/await will throw in a comment regarding <code>@MainActor</code> and how it can be used to ensure that any updates to the user interface will occur on the main thread.</p>
<p>That’s all well and good… but just where should the <code>@MainActor</code> attribute go? On the class? Only on the asynchronous function itself? Inside a nested Task block? On separate functions dedicated soley to updating the thread? Perhaps use something like <code>await MainActor.run</code> instead? Or should we just punt, use <code>DispatchQueue.main.async</code>, and forget the whole thing?</p>
<p>Lots of people have opinions on the matter, and this article is no different in that regard.</p>
<p>What is different, however, is that in <em>this</em> article we’re going to look at some of the actual SIL (Swift Intermediate Language) code generated by those mechanisms to examine the relative efficiency and code size of each.</p>
<p><a href="https://betterprogramming.pub/async-await-and-mainactor-strategies-cc35b6c58b52"><strong>Read More</strong></a></p>