Now that I got the concurrency toolchain running, I have another question: is it possible with the current toolchain (I'm using 2020-11-17) to write an async function that actually suspends?
I can write a function that is marked async but never actually suspends:
func compute() async -> Int {
return 42
}
But if I want to do something that's really asynchronous (say, perform some I/O or just sleep for a few seconds), if I understand correctly, I have to do one of two things:
-
Call a system API that is itself
async. These don't exist yet, for obvious reasons. Standard library APIs, such asTask.sleep, are not yet implemented in the current toolchain. -
Use
Task.withUnsafeContinuationto bridge between the async world and the old, callback-based world. This doesn't work becauseTask.withUnsafeContinuationand friends aren't implemented yet, either.
Is there another option?