07-19-2023, 01:22 AM
I'm trying to use async/await with Swift 5.5. I have my async function, but whenever I try to call it, I get this error:
> 'async' call in a function that does not support concurrency
Here's the code sample:
```swift
class TryThis {
func getSomethingLater(_ number: Double) async -> String {
// test - sleep for 3 seconds, then return
Thread.sleep(forTimeInterval: 3)
return String(format: ">>>%8.2f<<<", number)
}
}
let tryThis = TryThis()
let result = await tryThis.getSomethingLater(3.141592653589793238462)
print("result: \(result)")
```
What's the solution for this??
> 'async' call in a function that does not support concurrency
Here's the code sample:
```swift
class TryThis {
func getSomethingLater(_ number: Double) async -> String {
// test - sleep for 3 seconds, then return
Thread.sleep(forTimeInterval: 3)
return String(format: ">>>%8.2f<<<", number)
}
}
let tryThis = TryThis()
let result = await tryThis.getSomethingLater(3.141592653589793238462)
print("result: \(result)")
```
What's the solution for this??