Atom: Swift's actor implementation for .NET / Unity
Runtime/Threading/Atom.cs
(c) 2026 Sator Imaging, Licensed under the MIT License https://github.com/sator-imaging/Unity-Fundamentals
Basic Usage
var atom = new Atom<int>();
atom.Set = 310;
atom.Update = v => ++v; // Increments (311)
atom.Set = 42;
atom.Read = v => Console.WriteLine(v); // Prints 42
atom.WriteLock((x: 42, y: "Tuple"), static (args, current) =>
{
return current + args.x + args.y.Length;
});
If T is reference type, the object properties can be modified in read lock context.
var atom = new Atom<MyClass>(value: new());
atom.ReadLock(foo, static (foo, myClass) =>
{
// NOTE: Lock is taken until the operation finished.
// (e.g., For a second, other thread cannot access to the atom value at all)
System.Threading.Thread.Sleep(1000);
myClass.Data = foo.Value;
});