Can I use async in Playground? If so, please show an example.
func doStuff() async {
print("here")
}
doStuff()
print("After")
//error: 'async' call in a function that does not support concurrency
Like with every async function called from a synchronous context (the global context of your playground) you have to wrap your call to doStuff()
in an async
block and await
it:
async{
await doStuff()
}
This is expected to change to
Task.async{
await doStuff()
}
in a later beta.
The following list of WWDC videos covering Swift concurrency should provide further background: Meet Swift Concurrency