<div dir="ltr">I think we would be better off with a future type rather than async/await since they can offer timeout, cancel, and control over which thread execution occurs on.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"> -- Howard.<br></div></div>
<br><div class="gmail_quote">On 26 August 2017 at 00:06, Cavelle Benjamin via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Disclaimer: not an expert</div><div><br></div><div>Question</div><div>I didn’t see any where the async is required to time out after a certain time frame. I would think that we would want to specify both on the function declaration side as a default and on the function call side as a customization. That being said, the return time then becomes an optional given the timeout and the calling code would need to unwrap.</div><div><br></div><div><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;color:rgb(36,41,46)"><span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">loadWebResource</span>(<span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_2618414516455741937pl-smi" style="box-sizing:border-box">path</span>: <span class="m_2618414516455741937pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">String</span>) async <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Resource
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">decodeImage</span>(<span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_2618414516455741937pl-smi" style="box-sizing:border-box">r1</span>: Resource, <span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_2618414516455741937pl-smi" style="box-sizing:border-box">r2</span>: Resource) async <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Image
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">dewarpAndCleanupImage</span>(<span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_2618414516455741937pl-smi" style="box-sizing:border-box">i</span> : Image) async <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Image
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">processImageData1</span>() async <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Image {
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> dataResource <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="m_2618414516455741937pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">loadWebResource</span>(<span class="m_2618414516455741937pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="m_2618414516455741937pl-pds" style="box-sizing:border-box">"</span>dataprofile.<wbr>txt<span class="m_2618414516455741937pl-pds" style="box-sizing:border-box">"</span></span>)
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> imageResource <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="m_2618414516455741937pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">loadWebResource</span>(<span class="m_2618414516455741937pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="m_2618414516455741937pl-pds" style="box-sizing:border-box">"</span>imagedata.dat<span class="m_2618414516455741937pl-pds" style="box-sizing:border-box"><wbr>"</span></span>)
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> imageTmp <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="m_2618414516455741937pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">decodeImage</span>(dataResource, imageResource)
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> imageResult <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="m_2618414516455741937pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">dewarpAndCleanupImage</span>(<wbr>imageTmp)
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">return</span> imageResult
}</pre><div><br></div></div><div><br></div><div>So the prior code becomes… </div><div><br></div><div><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;color:rgb(36,41,46)"><span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">loadWebResource</span>(<span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_2618414516455741937pl-smi" style="box-sizing:border-box">path</span>: <span class="m_2618414516455741937pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">String</span>) async(timeout: 1000) <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Resource?
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">decodeImage</span>(<span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_2618414516455741937pl-smi" style="box-sizing:border-box">r1</span>: Resource, <span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_2618414516455741937pl-smi" style="box-sizing:border-box">r2</span>: Resource) async <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Image?
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">dewarpAndCleanupImage</span>(<span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">_</span> <span class="m_2618414516455741937pl-smi" style="box-sizing:border-box">i</span> : Image) async <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Image?
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_2618414516455741937pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">processImageData1</span>() async <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> Image? {
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> dataResource <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> guard let await <span class="m_2618414516455741937pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">loadWebResource</span>(<span class="m_2618414516455741937pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="m_2618414516455741937pl-pds" style="box-sizing:border-box">"</span>dataprofile.<wbr>txt<span class="m_2618414516455741937pl-pds" style="box-sizing:border-box">”</span></span>) else { // handle timeout }
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> imageResource <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> guard let await(timeout: 100) <span class="m_2618414516455741937pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">loadWebResource</span>(<span class="m_2618414516455741937pl-s" style="box-sizing:border-box;color:rgb(3,47,98)"><span class="m_2618414516455741937pl-pds" style="box-sizing:border-box">"</span>imagedata.dat<span class="m_2618414516455741937pl-pds" style="box-sizing:border-box"><wbr>”</span></span>) else { // handle timeout }
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> imageTmp <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="m_2618414516455741937pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">decodeImage</span>(dataResource, imageResource)
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">let</span> imageResult <span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">=</span> await <span class="m_2618414516455741937pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">dewarpAndCleanupImage</span>(<wbr>imageTmp)
<span class="m_2618414516455741937pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">return</span> imageResult
}</pre><div><br></div></div><div><br></div><div>Given this structure, the return type of all async’s would be optionals with now 3 return types??</div><div><br></div><div>.continuation // suspends and picks back up</div><div>.value // these are the values we are looking for</div><div>.none // took too long, so you get nothing.</div><div><br></div><div><br></div><br><div><blockquote type="cite"><div>On 2017-Aug -17 (34), at 18:24, Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_2618414516455741937Apple-interchange-newline"><div><div>Hi all,<br><br>As Ted mentioned in his email, it is great to finally kick off discussions for what concurrency should look like in Swift. This will surely be an epic multi-year journey, but it is more important to find the right design than to get there fast.<br><br>I’ve been advocating for a specific model involving async/await and actors for many years now. Handwaving only goes so far, so some folks asked me to write them down to make the discussion more helpful and concrete. While I hope these ideas help push the discussion on concurrency forward, this isn’t in any way meant to cut off other directions: in fact I hope it helps give proponents of other designs a model to follow: a discussion giving extensive rationale, combined with the long term story arc to show that the features fit together.<br><br>Anyway, here is the document, I hope it is useful, and I’d love to hear comments and suggestions for improvement:<br><a href="https://gist.github.com/lattner/31ed37682ef1576b16bca1432ea9f782" target="_blank">https://gist.github.com/<wbr>lattner/<wbr>31ed37682ef1576b16bca1432ea9f7<wbr>82</a><br><br>-Chris<span class=""><br><br>______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></span></div></div></blockquote></div><br></div><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>
<br></blockquote></div><br></div>