Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add part 2 #26

Merged
merged 2 commits into from Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -238,7 +238,7 @@ <h1>Structured Concurrency in Swift</h1><p>Swift 5.5 introduced structured concu
books.<span class="call">append</span>(book)
}
}
}</code></pre><h3>Discarding Task Groups</h3><p>In some cases, you might not be interested in the result of the task group. For example, you might want to run a number of tasks concurrently, but these tasks don't return results. In that case, you can use <code>withDiscardingTaskGroup</code> and <code>withThrowingDiscardingTaskGroup</code> from iOS 17 and macOS 14. This is a structured way to run multiple pieces of work concurrently, without needing to retain results.</p><p>The regular task groups create a collection of results, which you can then iterate over. In some cases, such as a TCP server, this collection of results is not needed and grow indefinitely. In that case, you'll want to use a discarding task group to prevent an ever-growing collection of results. Note that <code>Void</code> results are still stored and occupy a small amount of memory!</p><h2>Conclusion</h2><p>Structured concurrency is a powerful feature that was introduced with Swift 5.5. When writing your concurrenct code in a structured way, it's easier to reason about your code and maintain it.</p><p>Almost every application that you write will also have some form of shared state. In next week's article, we'll cover how Swift's actors, actor isolation and Sendable checking empower you to write race-condition free code.</p>
}</code></pre><h3>Discarding Task Groups</h3><p>In some cases, you might not be interested in the result of the task group. For example, you might want to run a number of tasks concurrently, but these tasks don't return results. In that case, you can use <code>withDiscardingTaskGroup</code> and <code>withThrowingDiscardingTaskGroup</code> from iOS 17 and macOS 14. This is a structured way to run multiple pieces of work concurrently, without needing to retain results.</p><p>The regular task groups create a collection of results, which you can then iterate over. In some cases, such as a TCP server, this collection of results is not needed and grow indefinitely. In that case, you'll want to use a discarding task group to prevent an ever-growing collection of results. Note that <code>Void</code> results are still stored and occupy a small amount of memory!</p><h2>Conclusion</h2><p>Structured concurrency is a powerful feature that was introduced with Swift 5.5. When writing your concurrenct code in a structured way, it's easier to reason about your code and maintain it.</p><p>Almost every application that you write will also have some form of shared state. In <a href="/structured-concurrency-and-shared-state-in-swift">the article</a>, we'll cover how Swift's actors, actor isolation and Sendable checking empower you to write race-condition free code.</p>

</section>

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions docs/index.html
Expand Up @@ -68,6 +68,19 @@ <h1>Swift on server</h1>

<div class="grid">
<div class="post">
<a href="https://swiftonserver.com/structured-concurrency-and-shared-state-in-swift/" target="">
<section>
<time datetime="2024/03/25">2024/03/25</time>
<h2 class="Structured Concurrency and Shared State in Swift">Structured Concurrency and Shared State in Swift</h2>
<p>Learn how actors and sendable prevent race conditions in your concurrent code.</p>
<div class="meta">
<span class="tag">Swift</span>
<span class="tag">Structured Concurrency</span>
</div>
</section>
</a>
</div>
<div class="post">
<a href="https://swiftonserver.com/getting-started-with-structured-concurrency-in-swift/" target="">
<section>
<time datetime="2024/03/19">2024/03/19</time>
Expand Down
11 changes: 9 additions & 2 deletions docs/rss.xml
Expand Up @@ -4,11 +4,18 @@
<description>Articles about server-side Swift development. Created by Joannis Orlandos and Tibor Bödecs.</description>
<link>https://swiftonserver.com/</link>
<language>en-US</language>
<lastBuildDate>Wed, 20 Mar 2024 17:30:36 +0000</lastBuildDate>
<pubDate>Mon, 18 Mar 2024 23:00:00 +0000</pubDate>
<lastBuildDate>Tue, 26 Mar 2024 09:45:37 +0000</lastBuildDate>
<pubDate>Sun, 24 Mar 2024 23:00:00 +0000</pubDate>
<ttl>250</ttl>
<atom:link href="https://swiftonserver.com/rss.xml" rel="self" type="application/rss+xml"/>

<item>
<guid isPermaLink="true">https://swiftonserver.com/structured-concurrency-and-shared-state-in-swift/</guid>
<title><![CDATA[ Structured Concurrency and Shared State in Swift ]]></title>
<description><![CDATA[ Learn how actors and sendable prevent race conditions in your concurrent code. ]]></description>
<link>https://swiftonserver.com/structured-concurrency-and-shared-state-in-swift/</link>
<pubDate>Sun, 24 Mar 2024 23:00:00 +0000</pubDate>
</item>
<item>
<guid isPermaLink="true">https://swiftonserver.com/getting-started-with-structured-concurrency-in-swift/</guid>
<title><![CDATA[ Getting Started with Structured Concurrency in Swift ]]></title>
Expand Down
38 changes: 21 additions & 17 deletions docs/sitemap.xml
@@ -1,38 +1,42 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://swiftonserver.com/using-swiftnio-fundamentals/</loc>
<lastmod>2024-03-20</lastmod>
<loc>https://swiftonserver.com/structured-concurrency-and-shared-state-in-swift/</loc>
<lastmod>2024-03-26</lastmod>
</url>
<url>
<loc>https://swiftonserver.com/developing-with-swift-in-visual-studio-code/</loc>
<lastmod>2024-03-20</lastmod>
<loc>https://swiftonserver.com/getting-started-with-structured-concurrency-in-swift/</loc>
<lastmod>2024-03-26</lastmod>
</url>
<url>
<loc>https://swiftonserver.com/using-swiftnio-channels/</loc>
<lastmod>2024-03-20</lastmod>
<loc>https://swiftonserver.com/using-environment-variables-in-swift/</loc>
<lastmod>2024-03-26</lastmod>
</url>
<url>
<loc>https://swiftonserver.com/building-swiftnio-clients/</loc>
<lastmod>2024-03-20</lastmod>
<loc>https://swiftonserver.com/using-openapi-with-hummingbird/</loc>
<lastmod>2024-03-26</lastmod>
</url>
<url>
<loc>https://swiftonserver.com/using-openapi-with-hummingbird/</loc>
<lastmod>2024-03-20</lastmod>
<loc>https://swiftonserver.com/whats-new-in-hummingbird-2/</loc>
<lastmod>2024-03-26</lastmod>
</url>
<url>
<loc>https://swiftonserver.com/getting-started-with-structured-concurrency-in-swift/</loc>
<lastmod>2024-03-20</lastmod>
<loc>https://swiftonserver.com/building-swiftnio-clients/</loc>
<lastmod>2024-03-26</lastmod>
</url>
<url>
<loc>https://swiftonserver.com/logging-for-server-side-swift-apps/</loc>
<lastmod>2024-03-20</lastmod>
<lastmod>2024-03-26</lastmod>
</url>
<url>
<loc>https://swiftonserver.com/whats-new-in-hummingbird-2/</loc>
<lastmod>2024-03-20</lastmod>
<loc>https://swiftonserver.com/using-swiftnio-channels/</loc>
<lastmod>2024-03-26</lastmod>
</url>
<url>
<loc>https://swiftonserver.com/using-environment-variables-in-swift/</loc>
<lastmod>2024-03-20</lastmod>
<loc>https://swiftonserver.com/using-swiftnio-fundamentals/</loc>
<lastmod>2024-03-26</lastmod>
</url>
<url>
<loc>https://swiftonserver.com/developing-with-swift-in-visual-studio-code/</loc>
<lastmod>2024-03-26</lastmod>
</url>
</urlset>