An Atom Runtime is a bridge between Effect’s service system and Effect Atom’s reactive system. It takes a Layer (which contains your services) and creates a specialized runtime that knows how to:
- Provide those services to any Atom that needs them
- Execute Effects within the context of those services
- Handle the async lifecycle (loading, success, failure) automatically
Think of it this way: a regular Effect Runtime knows how to run Effects. An Atom Runtime knows how to run Effects and turn them into reactive Atoms that work with the Registry.
In atom-runtime.ts, add the following code:
import { Atom } from "@effect-atom/atom-react";
import { UserService } from "@/services/user-service";
export const atomRuntime = Atom.runtime(UserService.Default);We pass UserService.Default to Atom.runtime. This creates an Atom Runtime that has access to UserService. Any Atom created through this runtime can now call methods on UserService — like getUsers() and others we’ll add later — without manually providing the service..
The Atom Runtime exposes several methods for creating Atoms:
.atom(): Creates an Atom from an Effect.fn(): Creates a callable Atom (useful for mutations).pull(): Creates an Atom that pulls from a Stream
We’ll use the .atom() method to create our first Atom in the next chapter.