<p dir="auto"><a href="https://gist.github.com/stevejmason/2fab8149460a5565ef388f92cd2e478e">https://gist.github.com/stevejmason/2fab8149460a5565ef388f92cd2e478e</a></p>
<p dir="auto">When running the above gist with Deno, the process crashes with <code class="notranslate">BorrowMutError</code>, see Actual text below. I believe this is caused by the mutable borrow calls within the async blocks on <code class="notranslate">cli/ops/net.rs:144</code> and <code class="notranslate">cli/ops/net.rs:212</code>.</p>
<p dir="auto">Perhaps we can use <code class="notranslate">tokio::net::udpsocket split()</code> and update <code class="notranslate">UdpSocketResource</code> to have a send/recv half contained in <code class="notranslate">Arc&lt;Mutex&lt;&gt;&gt;</code>, borrow state immutably on the main thread, clone the Arc container and use this from the async block? I have a working version to push, but would like some feedback on this approach as I'm fairly new to Rust.</p>
<p dir="auto">(<strong>sidenote</strong>, the gist is unlikely to run on master due to the new NetAddr/UnixAddr interfaces, I've been playing with types to add generics to <code class="notranslate">DatagramImpl</code> which i'll follow up with).</p>
<h3 dir="auto">Actual output</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="thread 'main' panicked at 'already borrowed: BorrowMutError', /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/cell.rs:878:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace"><pre class="notranslate"><code class="notranslate">thread 'main' panicked at 'already borrowed: BorrowMutError', /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/cell.rs:878:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</code></pre></div>
<h3 dir="auto">Expected output (duplicate lines removed)</h3>
<p dir="auto">Using fork - <a href="https://github.com/stevejmason/deno/tree/async-udp">https://github.com/stevejmason/deno/tree/async-udp</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TEST SOCKET RECV (1): hello world ! from [127.0.0.1:44444]
TEST SOCKET RECV (...10): hello world ! from [127.0.0.1:44444]
Received: [This is a response for message (1)] from (127.0.0.1:25262)
Received: [This is a response for message (...10)] from (127.0.0.1:25262)"><pre class="notranslate"><code class="notranslate">TEST SOCKET RECV (1): hello world ! from [127.0.0.1:44444]
TEST SOCKET RECV (...10): hello world ! from [127.0.0.1:44444]
Received: [This is a response for message (1)] from (127.0.0.1:25262)
Received: [This is a response for message (...10)] from (127.0.0.1:25262)
</code></pre></div>
<h3 dir="auto">Deno version (also <code class="notranslate">master#2874664</code>)</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deno 0.36.0
v8 8.1.310
typescript 3.8.3"><pre class="notranslate"><code class="notranslate">deno 0.36.0
v8 8.1.310
typescript 3.8.3
</code></pre></div>
<h4 dir="auto"><a href="http://server01/a.jsx" rel="nofollow">http://server01/a.jsx</a></h4>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import React from &quot;http://server01/react.js&quot;;

..."><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-v">React</span> <span class="pl-k">from</span> <span class="pl-s">"http://server01/react.js"</span><span class="pl-kos">;</span>

...</pre></div>
<h4 dir="auto"><a href="http://server02/b.jsx" rel="nofollow">http://server02/b.jsx</a></h4>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import React from &quot;http://server02/react.js&quot;;
..."><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-v">React</span> <span class="pl-k">from</span> <span class="pl-s">"http://server02/react.js"</span><span class="pl-kos">;</span>
...</pre></div>
<h4 dir="auto">main.jsx</h4>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import {A} from &quot;http://server01/a.jsx&quot;;
import {B} from &quot;http://server02/b.jsx&quot;;
...
return &lt;div&gt;
    &lt;A/&gt;
    &lt;B/&gt;
&lt;/div&gt;
...
 "><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-v">A</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"http://server01/a.jsx"</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-v">B</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"http://server02/b.jsx"</span><span class="pl-kos">;</span>
...
<span class="pl-k">return</span> <span class="pl-c1">&lt;</span><span class="pl-ent">div</span><span class="pl-c1">&gt;</span>
    <span class="pl-c1">&lt;</span><span class="pl-ent">A</span><span class="pl-c1">/</span><span class="pl-c1">&gt;</span>
    <span class="pl-c1">&lt;</span><span class="pl-ent">B</span><span class="pl-c1">/</span><span class="pl-c1">&gt;</span>
<span class="pl-c1">&lt;</span><span class="pl-c1">/</span><span class="pl-ent">div</span><span class="pl-c1">&gt;</span>
<span class="pl-kos">.</span><span class="pl-kos">.</span><span class="pl-kos">.</span>
 </pre></div>