[swift-evolution] [Concurrency] Fixing race conditions in async/await example

Adam Kemp adam.kemp at apple.com
Mon Aug 28 15:31:10 CDT 2017



> On Aug 28, 2017, at 1:14 PM, Florent Vilmart <florent at flovilmart.com> wrote:
> 
> I can see where you're going with that. 
> For me, the big unknown (and unspecified so far) is
> 
> func process() async -> Image { ... }
> 
> let result = process() // what is result? CoroutineType<Image> ? 
> 
> or am I missing something here?

By the rules of the proposal I think this is a compiler error.

In C# the async keyword does not affect the caller at all. The above example would be like this (using C# syntax):

Task<Image> Process();

Task<Image> result1 = Process();
Image result2 = await Process();

Some people dislike this behavior. If you forget the await keyword you get the future type instead of the actual result. That’s a little bit confusing.

However, you would only be confused until you try to compile your code and find that the type isn’t what you think it is. I can’t think of a scenario in which you would actually be able to compile the code and get the wrong result and have trouble understanding why. You would just get an error from the compiler when trying to access properties that don’t exist (or, more likely, notice that code completion is not giving you what you expect).

Personally I think this is a feature, not a bug. This is what allows you to easily mix async/await with futures.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170828/4b571bad/attachment.html>


More information about the swift-evolution mailing list