<story><title>Inside Rust&apos;s Async Transform</title><url>https://blag.nemo157.com/2018/12/09/inside-rusts-async-transform.html</url></story><parent_chain></parent_chain><comment><author>2bitencryption</author><text>Async&amp;#x2F;await pattern always confuses me, someone please let me know if I get this right:&lt;p&gt;First, async&amp;#x2F;await does NOT mean &amp;quot;threading&amp;quot; or &amp;quot;multiprocessing&amp;quot; or &amp;quot;concurrency&amp;quot;.  It simply means &amp;quot;using a state machine to alternate between tasks, which may or may not be concurrent.&amp;quot;  Right?&lt;p&gt;Further, in Javascript, futures and async are utilized heavily because we so frequently need to wait for IO events (i.e.: network events) to complete, and we don&amp;#x27;t want to block execution of the entire page just to wait for a IO to complete.  So the JS engine allows you to fire off these network events, do something else in the meantime, and then execute the &amp;quot;done&amp;quot; behavior when the IO is complete (and even in this case, we might not be concurrent, because ).&lt;p&gt;That makes sense to me.&lt;p&gt;But say I have written something in Rust that makes use of async&amp;#x2F;await.  And say there is absolutely no IO or multithreading.  Say I have some awaitable function called &amp;quot;compute_pi_digits()&amp;quot; that can take arbitrarily long to complete but does not do IO, it&amp;#x27;s purely computational.  Is there any benefit to making this function awaitable?  Unless I actually spawn it in a different thread, the awaitable version of this function will behave identically to if it were NOT awaitable, correct?&lt;p&gt;And one last idea: the async&amp;#x2F;await pattern is becoming so popular across vastly different languages because it allows us to abstract over concepts like concurrency, futures, promises, etc.  It&amp;#x27;s a bit of a &amp;quot;one size fits all&amp;quot; regardless of whether you&amp;#x27;re spinning up a thread, polling for a network event, setting up a callback for a future, etc?</text></comment>
<story><title>Inside Rust&apos;s Async Transform</title><url>https://blag.nemo157.com/2018/12/09/inside-rusts-async-transform.html</url></story><parent_chain></parent_chain><comment><author>benaadams</author><text>&amp;gt; is very different to other well-known implementations (C# and JavaScript [...]). Instead of performing a CPS-like transform where an async function is split into a series of continuations that are chained together via a Future::then method, Rust instead uses a generator&amp;#x2F;coroutine transform to turn the function into a state machine.&lt;p&gt;C# async&amp;#x2F;await is also very much resumable state machines</text></comment>