<p dir="auto">i tryin to build a port scanner with Deno<br>
Deno.connect() need timeout for close tcp connection<br>
i want when create connection after few seconds If did not get an answer do abort</p>
<p dir="auto">like a nodejs:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const { Socket } = require(&quot;net&quot;);
const socket = new Socket();
socket.on(&quot;timeout&quot;, () =&gt; {
    socket.destroy();
});
socket.setTimeout(200);
socket.connect(80, '8.8.8.8');"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-kos">{</span> Socket <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"net"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">socket</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Socket</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">on</span><span class="pl-kos">(</span><span class="pl-s">"timeout"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">destroy</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">setTimeout</span><span class="pl-kos">(</span><span class="pl-c1">200</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">socket</span><span class="pl-kos">.</span><span class="pl-en">connect</span><span class="pl-kos">(</span><span class="pl-c1">80</span><span class="pl-kos">,</span> <span class="pl-s">'8.8.8.8'</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">thanks</p>
<p dir="auto">Hey,</p>
<p dir="auto">It would be really cool if Deno aligned with the web platform's cancellation primitive AbortSignal/AbortController which Deno already supports but not in most of its APIs.</p>
<p dir="auto">Myself and a few others have been adding support for AbortSignal to all of the APIs it fits in Node.js to make it easier for people to write universal JavaScript code. For example:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Deno.readTextFile('./someFile', { signal });
Deno.writeTextFile('./someFile', { signal });"><pre class="notranslate"><span class="pl-v">Deno</span><span class="pl-kos">.</span><span class="pl-en">readTextFile</span><span class="pl-kos">(</span><span class="pl-s">'./someFile'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> signal <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-v">Deno</span><span class="pl-kos">.</span><span class="pl-en">writeTextFile</span><span class="pl-kos">(</span><span class="pl-s">'./someFile'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> signal <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">And more generally - in Deno's stream abstractions. Would you be open to adding this?</p>
<p dir="auto">(Sorry for not being too available on Discord with the baby/health stuff/new job :))</p>