<?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>DEV Community: Bruno Alves</title>
    <description>The latest articles on DEV Community by Bruno Alves (@nitoba).</description>
    <link>https://dev.to/nitoba</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4073519%2Fbfd9a0fc-d573-4823-8a45-9d41c32054f2.png</url>
      <title>DEV Community: Bruno Alves</title>
      <link>https://dev.to/nitoba</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nitoba"/>
    <language>en</language>
    <item>
      <title>Typed Errors Weren't Enough, So I Built better-effect</title>
      <dc:creator>Bruno Alves</dc:creator>
      <pubDate>Tue, 11 Aug 2026 17:53:51 +0000</pubDate>
      <link>https://dev.to/nitoba/typed-errors-werent-enough-so-i-built-better-effect-cki</link>
      <guid>https://dev.to/nitoba/typed-errors-werent-enough-so-i-built-better-effect-cki</guid>
      <description>&lt;h1&gt;
  
  
  Typed Errors Weren't Enough, So I Built better-effect
&lt;/h1&gt;

&lt;p&gt;I had already moved an important part of my application code away from exceptions and into Result types.&lt;/p&gt;

&lt;p&gt;That felt like a real improvement.&lt;/p&gt;

&lt;p&gt;A function no longer returned &lt;code&gt;User&lt;/code&gt; while quietly throwing five different exceptions. Its return type could describe both the successful value and the failures callers were expected to handle.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;better-result&lt;/code&gt;, I could also compose those operations using generators without losing the error channel.&lt;/p&gt;

&lt;p&gt;But the application could still compile and fail at startup because I forgot to provide a dependency.&lt;/p&gt;

&lt;p&gt;The errors were typed.&lt;/p&gt;

&lt;p&gt;The application wiring wasn't.&lt;/p&gt;

&lt;p&gt;That gap became the starting point for &lt;code&gt;better-effect&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Result describes failure, but not the whole environment
&lt;/h2&gt;

&lt;p&gt;Imagine a method with this return type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;UserNotFound&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;DatabaseFailure&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It tells us quite a lot.&lt;/p&gt;

&lt;p&gt;We know what success looks like. We know which failures belong to the operation. We can make callers handle those failures without relying on documentation or hidden exceptions.&lt;/p&gt;

&lt;p&gt;But the type still doesn't answer a few other questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where does the database come from?&lt;/li&gt;
&lt;li&gt;Which Services does the operation need?&lt;/li&gt;
&lt;li&gt;Did the application provide all of them?&lt;/li&gt;
&lt;li&gt;Can this operation run in the current environment?&lt;/li&gt;
&lt;li&gt;Who owns the connection?&lt;/li&gt;
&lt;li&gt;When should that connection be released?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those questions usually move somewhere else.&lt;/p&gt;

&lt;p&gt;They may live in constructor parameters, framework modules, a dependency injection container, a bootstrap file or test setup.&lt;/p&gt;

&lt;p&gt;That separation is normal, but it also means the code describing what an operation does and the code describing what it needs can easily fall out of sync.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let the code reveal its own requirements
&lt;/h2&gt;

&lt;p&gt;In &lt;code&gt;better-effect&lt;/code&gt;, a Service can be requested directly inside &lt;code&gt;Effect.gen&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Result&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;better-result&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Effect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Service&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;better-effect&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Database&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Service&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Database&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;findUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserRepository&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Service&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;UserRepository&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;findUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Effect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;yield&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;Database&lt;/span&gt;

      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The syntax is small:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;yield&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;Database&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But there are two things happening.&lt;/p&gt;

&lt;p&gt;At runtime, the Service is resolved from the current environment.&lt;/p&gt;

&lt;p&gt;At typecheck time, &lt;code&gt;Database&lt;/code&gt; becomes part of the requirements carried by that Effect.&lt;/p&gt;

&lt;p&gt;The dependency comes from the code that actually uses it. There is no second list to maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layers carry both sides of the environment
&lt;/h2&gt;

&lt;p&gt;A Layer describes an implementation that belongs to the application environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UserRepositoryLive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Layer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;UserRepository&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UserRepository&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Layer provides &lt;code&gt;UserRepository&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But the methods of &lt;code&gt;UserRepository&lt;/code&gt; use &lt;code&gt;Database&lt;/code&gt;, so the Layer also carries that requirement.&lt;/p&gt;

&lt;p&gt;If we try to create a Runtime from this incomplete environment, TypeScript rejects it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;UserRepositoryLive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;backend&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//                 ^^^^^^^^^^^^^^^^^^&lt;/span&gt;
&lt;span class="c1"&gt;// Database is required but not provided&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing needs to boot before the problem appears.&lt;/p&gt;

&lt;p&gt;The DI backend doesn't need to throw.&lt;/p&gt;

&lt;p&gt;A request doesn't need to hit the affected code path.&lt;/p&gt;

&lt;p&gt;The environment is incomplete, so the application doesn't typecheck.&lt;/p&gt;

&lt;p&gt;Adding the missing implementation completes it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DatabaseLive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Layer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AppLive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Layer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;DatabaseLive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;UserRepositoryLive&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;runtime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AppLive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;backend&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Typechecked wiring
&lt;/h2&gt;

&lt;p&gt;I've been calling this relationship &lt;strong&gt;typechecked wiring&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It connects three parts of the application:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the Services the code uses;&lt;/li&gt;
&lt;li&gt;the implementations the Layers provide;&lt;/li&gt;
&lt;li&gt;the programs a Runtime can execute.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yield* Database
      │
      ▼
the program requires Database
      │
      ▼
does the Layer provide Database?
      │
   no ├──────────► TypeScript error
      │
     yes
      ▼
the Runtime can execute the program
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Runtime keeps the exact Service environment inferred from its Layer.&lt;/p&gt;

&lt;p&gt;That means the contract remains useful after startup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;Effect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;yield&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;Database&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the program asks for a Service that doesn't exist in that Runtime, TypeScript rejects the call.&lt;/p&gt;

&lt;p&gt;This matters in applications with more than one environment.&lt;/p&gt;

&lt;p&gt;A web server, a worker, a migration script and a test suite may all run different programs against different sets of Services.&lt;/p&gt;

&lt;p&gt;The Runtime type makes that distinction visible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Replacing implementations without losing the contract
&lt;/h2&gt;

&lt;p&gt;Tests often need the same application structure with a different implementation.&lt;/p&gt;

&lt;p&gt;Layers can be overridden explicitly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AppTest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Layer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;override&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;AppLive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;DatabaseTest&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database implementation changes, but the environment doesn't become untyped.&lt;/p&gt;

&lt;p&gt;The resulting Layer still knows which Services it provides and which requirements remain.&lt;/p&gt;

&lt;p&gt;This makes test environments easier to reason about without forcing application code to depend directly on a specific container.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some dependencies also have a lifetime
&lt;/h2&gt;

&lt;p&gt;Providing the correct object is only part of resource management.&lt;/p&gt;

&lt;p&gt;A database connection, transaction, file or session also needs an owner.&lt;/p&gt;

&lt;p&gt;Who is responsible for releasing it?&lt;/p&gt;

&lt;p&gt;Does it live for one request, one job or the whole application?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;better-effect&lt;/code&gt; uses &lt;code&gt;Scope&lt;/code&gt; to make that ownership explicit.&lt;/p&gt;

&lt;p&gt;A resource acquired by a scoped Layer belongs to the Runtime:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DatabaseLive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Layer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scoped&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It remains alive while the application Runtime is active.&lt;/p&gt;

&lt;p&gt;A resource acquired inside a program belongs to that execution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;yield&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;Effect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;acquireRelease&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reserve&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;release&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the execution ends, the resource is released.&lt;/p&gt;

&lt;p&gt;This also allows cleanup logic to see whether the execution succeeded or failed, which is useful for cases such as commit and rollback.&lt;/p&gt;

&lt;p&gt;During shutdown, the Runtime stops accepting new executions, waits for active ones to finish, releases scoped resources and finally disposes the configured backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why build this instead of using Effect directly?
&lt;/h2&gt;

&lt;p&gt;Effect already has strong answers for dependencies, environments, resources, concurrency and many other application concerns.&lt;/p&gt;

&lt;p&gt;It also has a full runtime, fibers, structured concurrency, streams, schedules, queues and a broader ecosystem.&lt;/p&gt;

&lt;p&gt;For applications that want that complete model, using Effect directly makes sense.&lt;/p&gt;

&lt;p&gt;The question behind &lt;code&gt;better-effect&lt;/code&gt; is slightly different:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What if I want some of those architectural guarantees, but I want to keep &lt;code&gt;better-result&lt;/code&gt;, Promises and the runtime my application already uses?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That choice defines the limits of the project.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;better-effect&lt;/code&gt; doesn't provide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;fibers;&lt;/li&gt;
&lt;li&gt;a custom scheduler;&lt;/li&gt;
&lt;li&gt;streams or queues;&lt;/li&gt;
&lt;li&gt;a public &lt;code&gt;Effect&amp;lt;A, E, R&amp;gt;&lt;/code&gt; type;&lt;/li&gt;
&lt;li&gt;its own complete dependency injection container;&lt;/li&gt;
&lt;li&gt;a second error model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Effect.gen&lt;/code&gt; delegates Result composition to &lt;code&gt;better-result&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Dependency resolution and caching stay behind a backend. The core library is concerned with the contract around Services, environments and lifetimes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where better-effect fits
&lt;/h2&gt;

&lt;p&gt;The project is mainly aimed at TypeScript developers who already like Result-based code but are reaching the point where error handling is no longer the only architectural concern.&lt;/p&gt;

&lt;p&gt;It may be useful in projects that have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;application Services and repositories;&lt;/li&gt;
&lt;li&gt;an explicit composition root;&lt;/li&gt;
&lt;li&gt;production and test environments;&lt;/li&gt;
&lt;li&gt;Clean Architecture or DDD boundaries;&lt;/li&gt;
&lt;li&gt;resources that need clear ownership;&lt;/li&gt;
&lt;li&gt;an existing DI container they don't want to replace.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It won't be the right tool for every application.&lt;/p&gt;

&lt;p&gt;When Result types and generator composition are enough, &lt;code&gt;better-result&lt;/code&gt; can be used on its own.&lt;/p&gt;

&lt;p&gt;When the application wants a complete effect system and runtime, Effect is the stronger choice.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;better-effect&lt;/code&gt; is exploring the smaller space between those two options.&lt;/p&gt;

&lt;h2&gt;
  
  
  The project is open source
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;better-effect&lt;/code&gt; is open source and available under the MIT license.&lt;/p&gt;

&lt;p&gt;You can install it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;better-effect better-result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The project is still early, and I'm deliberately trying to keep the API small.&lt;/p&gt;

&lt;p&gt;At this stage, I'm especially interested in feedback about the model itself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does the Service API feel natural?&lt;/li&gt;
&lt;li&gt;Are incomplete-environment errors understandable?&lt;/li&gt;
&lt;li&gt;Does “typechecked wiring” describe the benefit clearly?&lt;/li&gt;
&lt;li&gt;Which responsibilities should stay outside the library?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Typed errors already make application code easier to understand.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;better-effect&lt;/code&gt; is an experiment in bringing the same kind of visibility to application wiring and resource ownership.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nitoba/better-effect" rel="noopener noreferrer"&gt;Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/better-effect" rel="noopener noreferrer"&gt;Package&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
    </item>
  </channel>
</rss>
