<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="728455034" data-permission-text="Title is private" data-url="https://github.com/denodrivers/mysql/issues/87" data-hovercard-type="issue" data-hovercard-url="/denodrivers/mysql/issues/87/hovercard" href="https://github.com/denodrivers/mysql/issues/87">denodrivers/mysql#87</a><br>
I have used <code class="notranslate">setTimeout</code> to implement the idle connection timeout for the connection pool.<br>
But when user write some short-running app like this:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const client = new Client().connect(/* ... */);
console.log(await client.query(&quot;SELECT ...&quot;));
// End of file, but Deno won't exit"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">client</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Client</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">connect</span><span class="pl-kos">(</span><span class="pl-c">/* ... */</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-k">await</span> <span class="pl-s1">client</span><span class="pl-kos">.</span><span class="pl-en">query</span><span class="pl-kos">(</span><span class="pl-s">"SELECT ..."</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">// End of file, but Deno won't exit</span></pre></div>
<p dir="auto">Deno won't exit after it finishes querying. It still waits for some timer (by <code class="notranslate">setTimeout</code>) that can close pooled connection when it stayed idle for too long.</p>
<p dir="auto">I think there should be a timer API that won't prevent Deno from exiting automatically.</p>
<p dir="auto"><strong>Use case</strong>:  As a a module developer, I want to run periodic tasks during the execution of my module.  This can be accomplished via <code class="notranslate">setTimeout</code> or <code class="notranslate">setInterval</code> for example.  However, I do not want these timers to block the exiting of my module.  <code class="notranslate">setInterval</code> in particular will cause the module to run forever until the <code class="notranslate">id</code> associated with it is cleared.</p>
<p dir="auto"><strong>Specific use case</strong>:  <code class="notranslate">std/log</code> file handler now uses a buffer to write log messages.  Google and Go's glog implementations both use a log daemon to flush the buffer automatically every 30 seconds.  It would be good for <code class="notranslate">std/log</code> file handler to use <code class="notranslate">setInterval</code> to flush the buffer every 30 seconds as well to mimic this but not block module exit. (see also ref <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="631737804" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/6127" data-hovercard-type="pull_request" data-hovercard-url="/denoland/deno/pull/6127/hovercard" href="https://github.com/denoland/deno/pull/6127">#6127</a>)</p>
<p dir="auto">For starters, there is already support for <a href="https://github.com/denoland/deno/blob/master/core/ops.rs#L20">async unref ops</a> within Deno which would likely be used in this solution.</p>