<div dir="ltr">Sorry, I&#39;m just getting into this conversation late and am by no means experienced in the area, but why can&#39;t the one where you *don&#39;t* want the caller to wait for the result be spelled `async -&gt; Never`? Theoretically, `async -&gt; Void` means you&#39;re awaiting a result with only one possible value, but if you&#39;re not waiting at all, then there is truly no result, yes?<div><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 12, 2017 at 9:27 AM, Yuta Koshizawa via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sorry, I had got some confusion. Please let me retry to explain.<br>
<br>
As you said, C# provides three kinds of async functions: `async Void`,<br>
`async Task` and `async Task&lt;Foo&gt;`. All of them are necessary and<br>
Swift should provide same functionalities.<br>
<br>
When we think about `async/await` in Swift, because we have already<br>
had `throws/try`, it is desired that `async/await` in Swift is<br>
consistent with `throws/try`. So it is better to have `async/await`<br>
without introducing a type like `Task` (or `Promise`).<br>
<br>
Even if we employ `async/await` without `Task`, Swift has to provides<br>
functionalities to implement &quot;three kinds of async functions&quot; in C#.<br>
However if `async -&gt; Void` in Swift works similarly to `async Void` in<br>
C#, how can we express ones like `async Task` in C#? I think there are<br>
two possibilities:<br>
<br>
1. Calling `async -&gt; Void` functions without `await` in Swift works<br>
like `async Void` in C# and calling them *with* `await` works like<br>
`async Task` in C#.<br>
2. Calling `async -&gt; Void` functions without `await` in Swift works<br>
like `async Void` in C# and never support something like `async Task`<br>
in C#.<br>
<br>
I think 2 is impermissible. For example, handling completion events of<br>
asynchronous operations without result values needs something like<br>
`async Task` in C#. However, with 1, we lose the benefit of static<br>
checks by the compiler. Because both of `fooAsync()` without `await`<br>
and `await fooAsync()` are allowed, even if we want it to work like<br>
`async Task` in C# and forget to mark `await`, the compiler tell us<br>
nothing and it works like `async Void` in C#. It causes unexpected<br>
behaviors. It is hard to fix such kinds of bugs. So I think<br>
introducing `beginAsync` is better.<br>
<br>
--<br>
Yuta<br>
<br>
<br>
2017-11-12 10:23 GMT+09:00 Yuta Koshizawa via swift-evolution<br>
&lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br>
<div class="HOEnZb"><div class="h5">&gt; 2017-11-12 2:57 GMT+09:00 Adam Kemp &lt;<a href="mailto:adam.kemp@apple.com">adam.kemp@apple.com</a>&gt;:<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;&gt; On Nov 11, 2017, at 6:24 AM, Yuta Koshizawa &lt;<a href="mailto:koher@koherent.org">koher@koherent.org</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; If you replace `async` with `throws`, you can get answers.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Can you declare an async closure variable?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Yes. Like `let throwingClosure:() throws -&gt; Void = { ... }`.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Can a non-async closure be passed to a function expecting a async closure?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Yes. Like we can pass `() -&gt; Void` to a function expecting a throwing<br>
&gt;&gt;&gt; closure `() throws -&gt; Void`.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; It is possible because `(Foo) throws -&gt; Bar` is a supertype of `(Foo)<br>
&gt;&gt;&gt; -&gt; Bar`. `(Foo) async -&gt; Bar` is a supertype of `(Foo) -&gt; Bar` in the<br>
&gt;&gt;&gt; same way.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; To treat an async function as a sync function is legal. It is similar<br>
&gt;&gt;&gt; to make a `Promise` by `Promise(value)` which is completed<br>
&gt;&gt;&gt; immediately.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Can an async closure be passed to a function expecting a non-async closure?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; No. `() -&gt; Void` is a subtype of `() async -&gt; Void`. It is same as<br>
&gt;&gt;&gt; passing `() throws -&gt; Void` to a function expecting `() -&gt; Void` is<br>
&gt;&gt;&gt; not allowed.<br>
&gt;&gt;<br>
&gt;&gt; But why not? Just asserting that it must work the same as throws<br>
&gt;&gt; is not a convincing argument. You have to justify why it must work<br>
&gt;&gt; that way. I think there is good reason to allow it, which I have described.<br>
&gt;&gt; What reason is there to disallow it?<br>
&gt;<br>
&gt; `() async -&gt; Void` needs to be called with `await` because it prevents<br>
&gt; us from forgetting handling asynchronous operations.<br>
&gt;<br>
&gt; If we use callbacks to handle asynchronous operations, it is shown to<br>
&gt; us by a compiler as a compilation error.<br>
&gt;<br>
&gt; ```<br>
&gt; func fooAsync(_ handler: () -&gt; Void) -&gt; Void { ... }<br>
&gt;<br>
&gt; fooAsync() // compilation error<br>
&gt;<br>
&gt; fooAsync {<br>
&gt;   // handles a completion event here<br>
&gt; }<br>
&gt; ```<br>
&gt;<br>
&gt; With proposed `async/await`, it is realized similarly like below.<br>
&gt;<br>
&gt; ```<br>
&gt; func fooAsync() async -&gt; Void { ... }<br>
&gt;<br>
&gt; fooAsync() // compilation error<br>
&gt;<br>
&gt; await fooAsync()<br>
&gt; // handles a completion event here<br>
&gt; ```<br>
&gt;<br>
&gt; However, if async void functions work like `beginAsync`, we can easily<br>
&gt; forget it and it can cause unexpected behaviors.<br>
&gt;<br>
&gt; ```<br>
&gt; func fooAsync() async -&gt; Void { ... }<br>
&gt;<br>
&gt; fooAsync() // OK<br>
&gt; // hard to know this line is executed asynchronously<br>
&gt; ```<br>
&gt;<br>
&gt; Readability also suffers seriously. If we don&#39;t know `bar` in the<br>
&gt; following code is a async function, it is impossible to expect lines<br>
&gt; after `baz()` are executed asynchronously.<br>
&gt;<br>
&gt; ```<br>
&gt; foo()<br>
&gt; bar()<br>
&gt; baz()<br>
&gt; qux()<br>
&gt; ```<br>
&gt;<br>
&gt;<br>
&gt;&gt;&gt;&gt; It’s weird to me that we would allow you to have async void closures but not async void functions<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I am not sure what you mean. &quot;async void closures&quot; and &quot;async void<br>
&gt;&gt;&gt; functions&quot; have a same type. Following two are almost same.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; ```<br>
&gt;&gt;&gt; func foo() async -&gt; Void { ... }<br>
&gt;&gt;&gt; let foo: () async -&gt; Void = { ... }<br>
&gt;&gt;&gt; ```<br>
&gt;&gt;<br>
&gt;&gt; What started this thread is my suggestion that you should be able to write<br>
&gt;&gt; an async void function. The current proposal doesn’t allow that. That’s why<br>
&gt;&gt; you have to use beginAsync.<br>
&gt;&gt;<br>
&gt;&gt; I don’t think that makes sense. It sounds like you also think that would be strange,<br>
&gt;&gt; hence your assumption that you could.<br>
&gt;<br>
&gt; By the reasons I wrote above, we need `await` even for async void<br>
&gt; functions for checks by compilers. Then it is required to provide a<br>
&gt; way to write entry points of async functions. That is `beginAsync`.<br>
&gt;<br>
&gt; --<br>
&gt; Yuta<br>
&gt; ______________________________<wbr>_________________<br>
&gt; swift-evolution mailing list<br>
&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</div></div></blockquote></div><br></div></div></div>