<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Sync on Nalar</title>
    <link>https://nalar.dev/tags/sync/</link>
    <description>Recent content in Sync on Nalar</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 02 Sep 2026 00:00:00 +0700</lastBuildDate>
    <atom:link href="https://nalar.dev/tags/sync/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Lazy Initialization in Go with sync.OnceValue and sync.OnceValues</title>
      <link>https://nalar.dev/lazy-initialization-with-sync-oncevalue-and-oncevalues/</link>
      <pubDate>Wed, 02 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/lazy-initialization-with-sync-oncevalue-and-oncevalues/</guid>
      <description>&lt;p&gt;Lazy initialization is useful when a value is expensive to build and may never be needed. The difficulty is making that initialization safe when several goroutines request the value at the same time.&lt;/p&gt;&#xA;&lt;p&gt;Go has long provided &lt;code&gt;sync.Once&lt;/code&gt;. Since Go 1.21, the &lt;code&gt;sync&lt;/code&gt; package also includes &lt;code&gt;OnceValue&lt;/code&gt; and &lt;code&gt;OnceValues&lt;/code&gt;, helpers that return functions which compute results once and reuse them for later calls.&lt;/p&gt;&#xA;&lt;h2 id=&#34;the-manual-synconce-pattern&#34;&gt;The manual &lt;code&gt;sync.Once&lt;/code&gt; pattern&lt;/h2&gt;&#xA;&lt;p&gt;A classic implementation looks like this:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
