# Swift Concurrency Waits for No One

DevFeed: [Swift Concurrency Waits for No One](<https://devfeed.tech/articles/swift-concurrency-waits-for-no-one-27360.md>)

Original publisher: [Read original article](<https://saagarjha.com/blog/2023/12/22/swift-concurrency-waits-for-no-one/>)

Published: 2023-12-22T00:00:00Z

Content type: article

Language: en

Sources: [Saagar Jha](<https://devfeed.tech/sources/saagar-jha.md>)

Topics: [Swift](<https://devfeed.tech/topics/swift.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Concurrent Programming](<https://devfeed.tech/topics/concurrent-programming.md>), [Code](<https://devfeed.tech/topics/code.md>), [API](<https://devfeed.tech/topics/api.md>), [POSIX](<https://devfeed.tech/topics/posix.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [code](<https://devfeed.tech/tags/code.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [concurrent-programming](<https://devfeed.tech/tags/concurrent-programming.md>), [posix](<https://devfeed.tech/tags/posix.md>), [swift](<https://devfeed.tech/tags/swift.md>), [threads](<https://devfeed.tech/tags/threads.md>)

## AI overview

The article explains why Swift Concurrency requires careful handling when asynchronous work must be invoked from synchronous code and then awaited. It uses the example of spawning a Task and blocking with a semaphore to illustrate the complexity of preserving task forward progress, while contrasting Swift Concurrency with older concurrency APIs.

## Source excerpt

There was once a master engineer who lived by herself in a mystical, far off place, where nourishment flowed freely and the dirt beneath your feet was more valuable than gold. Inaccessible even by foot, only very few could make the trip for a chance at receiving her wisdom. A novice programmer, enthusiastic but still wet behind the ears, visited her one day. "I have read your code," he began, "and I can only describe it as sublime. But, I've been learning a lot about Swift Concurrency and I see that you don't use it all the time. Why is that?" The master engineer replied promptly with a question of her own: "Tell me, how would an asynchronous program call synchronous code?" "That's easy," he replied. "You can just call it directly." "Now, how would one invoke asynchronous code from a synchronous context?" "Spawn a Task, obviously!" replied the novice engineer, glad that his studies had come in handy. The master engineer smiled. "Very good. But now, imagine waiting for the work to complete before proceeding. What then? The API, naturally, is provided by the system and cannot be redesigned." This troubled the novice, and he furrowed his brow in concentration for some time. Finally, a half-forgotten memory came back to him: "DispatchSemaphore! I can use a semaphore to wait for the asynchronous work!" "Swift Concurrency requires tasks to make forward progress", responded the master engineer. Then she fell silent. After a while, the novice was enlightened.