[Accepted with Modification] SE-0296: async/await

Great example. Thanks. I wasn't sure if the compiler was magically going to reach into the function and find return values or what.

This syntax is very similar to that used in RxSwift when doing something like Single.create { }.

Although, true to form, it's pretty deep into standardSwiftRunOnSentence-land (withUnsafeThrowingContinuation indeed!).

Umm... if you don't mind my asking, why is the continuation considered unsafe? Because it may never be called?

The api docs have this line:

The operation functions must resume the continuation exactly once .

This is up to the consumers of the api and isn't enforced by the compiler, which I would assume is why they are labeled as unsafe.

3 Likes

Yes, that's exactly right. If you resume the continuation multiple times, the program will probably crash; if you don't resume it, the task and its parent tasks will hang forever and any resources tied up with them will leak.

2 Likes
Terms of Service

Privacy Policy

Cookie Policy