Skip to main content

How to fix the error “async call in a function that does not support concurrency”

About 2 minSwiftArticle(s)bloghackingwithswift.comcrashcourseswiftxcodeappstore

How to fix the error “async call in a function that does not support concurrency” 관련

Swift Concurrency by Example

Back to Home

How to fix the error “async call in a function that does not support concurrency” | Swift Concurrency by Example

How to fix the error “async call in a function that does not support concurrency”

Updated for Xcode 15

This error occurs when you’ve tried to call an async function from a synchronous function, which is not allowed in Swift – asynchronous functions must be able to suspend themselves and their callers, and synchronous functions simply don’t know how to do that.

If your asynchronous work needs to be waited for, you don’t have much of a choice but to mark your current code as also being async so that you can use await as normal. However, sometimes this can result in a bit of an “async infection” – you mark one function as being async, which means its caller needs to be async too, as does *its* caller, and so on, until you’ve turned one error into 50.

In this situation, you can create a dedicated Task to solve the problem. We’ll be covering this API in more detail later on, but here’s how it would look in your code:

func doAsyncWork() async {
    print("Doing async work")
}

func doRegularWork() {
    Task {
        await doAsyncWork()
    }
}

doRegularWork()

Download this as an Xcode projectopen in new window

Tasks like this one are created and run immediately. We aren’t waiting for the task to complete, so we shouldn’t use await when creating it.

Similar solutions…
How to call an async function using async let | Swift Concurrency by Example

How to call an async function using async let
Why can’t we call async functions using async var? | Swift Concurrency by Example

Why can’t we call async functions using async var?
How to create and call an async function | Swift Concurrency by Example

How to create and call an async function
How to call async throwing functions | Swift Concurrency by Example

How to call async throwing functions
Concurrency vs parallelism | Swift Concurrency by Example

Concurrency vs parallelism

이찬희 (MarkiiimarK)
Never Stop Learning.