<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Adrian Brad</title>
    <description>The latest articles on Forem by Adrian Brad (@adrianbrad).</description>
    <link>https://forem.com/adrianbrad</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F849855%2Fa8836a6c-107b-4971-97f0-746ad3cd2ea5.png</url>
      <title>Forem: Adrian Brad</title>
      <link>https://forem.com/adrianbrad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/adrianbrad"/>
    <language>en</language>
    <item>
      <title>Go queue v1.7.0: a new Delay queue for timers, retries, and TTLs</title>
      <dc:creator>Adrian Brad</dc:creator>
      <pubDate>Tue, 21 Apr 2026 09:18:46 +0000</pubDate>
      <link>https://forem.com/adrianbrad/go-queue-v170-a-new-delay-queue-for-timers-retries-and-ttls-3h7g</link>
      <guid>https://forem.com/adrianbrad/go-queue-v170-a-new-delay-queue-for-timers-retries-and-ttls-3h7g</guid>
      <description>&lt;p&gt;I just tagged v1.7.0 of &lt;a href="https://github.com/adrianbrad/queue" rel="noopener noreferrer"&gt;github.com/adrianbrad/queue&lt;/a&gt;, a thread-safe generic queue package. The headline feature is a new &lt;code&gt;Delay&lt;/code&gt; queue.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Delay?
&lt;/h2&gt;

&lt;p&gt;Delay is a priority queue where each element becomes dequeuable at a deadline computed by a caller-supplied function at &lt;code&gt;Offer&lt;/code&gt; time. &lt;code&gt;Get&lt;/code&gt; returns &lt;code&gt;ErrNoElementsAvailable&lt;/code&gt; until the head is due; &lt;code&gt;GetWait&lt;/code&gt; sleeps until it is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;    &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;runAt&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Time&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;delayQueue&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewDelay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;runAt&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;20&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Millisecond&lt;/span&gt;&lt;span class="p"&gt;)},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;runAt&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Millisecond&lt;/span&gt;&lt;span class="p"&gt;)},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Time&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;runAt&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// Blocks until the earliest-deadline element is due.&lt;/span&gt;
&lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;delayQueue&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetWait&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Useful for retry scheduling, TTL expiry, timer wheels, and similar patterns where work should become visible at a future wall-clock time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Min-heap by deadline, written directly on a typed slice instead of via &lt;code&gt;container/heap&lt;/code&gt;. pprof showed &lt;code&gt;container/heap&lt;/code&gt;'s &lt;code&gt;any&lt;/code&gt;-boxing accounted for most of the allocations, so steady-state offer/get is now zero-alloc.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GetWait&lt;/code&gt; uses &lt;code&gt;sync.Cond&lt;/code&gt; + &lt;code&gt;time.AfterFunc&lt;/code&gt; so "head is due" and "queue state changed" compose under a single &lt;code&gt;Wait&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Peek&lt;/code&gt; returns the head regardless of whether its deadline has passed (matches &lt;code&gt;java.util.concurrent.DelayQueue.peek&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Five queues, one interface
&lt;/h2&gt;

&lt;p&gt;Delay joins Blocking, Priority, Circular, and Linked. All satisfy the same &lt;code&gt;Queue[T comparable]&lt;/code&gt; interface, so you can swap implementations without changing call sites. The README has a small decision table for picking one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: v1.6.0 shipped a lot
&lt;/h2&gt;

&lt;p&gt;Since the last post I also tagged v1.6.0, a heavy batch of correctness and performance work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Priority.MarshalJSON&lt;/code&gt; was emitting elements in arbitrary heap-array order; now emits in priority order.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Reset&lt;/code&gt; on Blocking, Circular, and Priority now honours capacity and zeros dropped slots (pointer &lt;code&gt;T&lt;/code&gt; was leaking).&lt;/li&gt;
&lt;li&gt;Blocking switched from Signal to Broadcast, removing a fragile cascade in &lt;code&gt;PeekWait&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Linked grew an internal node free list; steady-state offer/get dropped from 16 B / 1 alloc to 0.&lt;/li&gt;
&lt;li&gt;Capacity validation at construction time (panics with a clear message instead of a cryptic slice panic later).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Repo: &lt;a href="https://github.com/adrianbrad/queue" rel="noopener noreferrer"&gt;github.com/adrianbrad/queue&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Docs: &lt;a href="https://pkg.go.dev/github.com/adrianbrad/queue" rel="noopener noreferrer"&gt;pkg.go.dev/github.com/adrianbrad/queue&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>go</category>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Introducing PrivateBTC: A Go package providing an intuitive TUI and a streamlined API.</title>
      <dc:creator>Adrian Brad</dc:creator>
      <pubDate>Tue, 31 Oct 2023 09:08:08 +0000</pubDate>
      <link>https://forem.com/adrianbrad/introducing-privatebtc-a-go-package-providing-an-intuitive-tui-and-a-streamlined-api-3f2j</link>
      <guid>https://forem.com/adrianbrad/introducing-privatebtc-a-go-package-providing-an-intuitive-tui-and-a-streamlined-api-3f2j</guid>
      <description>&lt;p&gt;With PrivateBTC you can launch and manage your Bitcoin private network with ease. Execute and replace transactions by fee, mine blocks, and programmatically delve into chain reorganizations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/adrianbrad/privatebtc"&gt;https://github.com/adrianbrad/privatebtc&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bitcoin</category>
      <category>go</category>
      <category>tui</category>
    </item>
    <item>
      <title>Announcing v1.3.0 of my queue package implemented in Golang</title>
      <dc:creator>Adrian Brad</dc:creator>
      <pubDate>Tue, 24 Oct 2023 20:41:24 +0000</pubDate>
      <link>https://forem.com/adrianbrad/announcing-v130-of-my-queue-package-implemented-in-golang-4oie</link>
      <guid>https://forem.com/adrianbrad/announcing-v130-of-my-queue-package-implemented-in-golang-4oie</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/adrianbrad/queue"&gt;https://github.com/adrianbrad/queue&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm happy to announce that I've released v1.3.0 of my #queue #golang package: A Linked Queue implementation was added, complementing the Circular, Blocking, and Priority queues. All structures align with the standard Queue interface.&lt;/p&gt;

&lt;p&gt;The package also contains various artifacts that could interest a broader audience. These artifacts include: CI scripts(coverage, lint, testing), golang-ci lint config file, commitizen, example tests, benchmarks and documentation provided by godoc.&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>opensource</category>
    </item>
    <item>
      <title>I released v1.2.0 of my queues package implemented in Golang.</title>
      <dc:creator>Adrian Brad</dc:creator>
      <pubDate>Wed, 19 Apr 2023 12:52:23 +0000</pubDate>
      <link>https://forem.com/adrianbrad/i-released-v120-of-my-queues-package-implemented-in-golang-1h4e</link>
      <guid>https://forem.com/adrianbrad/i-released-v120-of-my-queues-package-implemented-in-golang-1h4e</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/adrianbrad/queue"&gt;https://github.com/adrianbrad/queue&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A Circular Queue implementation is now available. Blocking and Priority queues were previously available. All implementations satisfy the Queue interface provided by the package.&lt;/p&gt;

&lt;p&gt;The package also contains various artifacts that could interest a broader audience. These artifacts include: CI scripts(coverage, lint, testing), golang-ci lint config file, commitizen, example tests, benchmarks and documentation provided by godoc.&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>opensource</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Parallel Go tests executed against a PostgreSQL database running on Docker</title>
      <dc:creator>Adrian Brad</dc:creator>
      <pubDate>Tue, 19 Apr 2022 05:12:16 +0000</pubDate>
      <link>https://forem.com/adrianbrad/parallel-go-tests-executed-against-a-postgresql-database-running-on-docker-2m1m</link>
      <guid>https://forem.com/adrianbrad/parallel-go-tests-executed-against-a-postgresql-database-running-on-docker-2m1m</guid>
      <description>&lt;p&gt;Hello, I published an article explaining explaining how to run your Go tests in parallel against a PostgreSQL DB running on Docker. The PSQL container is created and destroyed programmatically, with Go, before and after running the tests.&lt;/p&gt;

&lt;p&gt;Medium article: &lt;a href="https://adrianbrad.medium.com/parallel-postgresql-tests-go-docker-6fb51c016796"&gt;https://adrianbrad.medium.com/parallel-postgresql-tests-go-docker-6fb51c016796&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Github repo with examples: &lt;a href="https://github.com/adrianbrad/psql-docker-tests-example"&gt;https://github.com/adrianbrad/psql-docker-tests-example&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>postgres</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
