NIOAtomic

An encapsulation of an atomic primitive object.

NIOAtomic.swift:223

This declaration is deprecated: please use ManagedAtomic from https://github.com/apple/swift-atomics instead

final class NIOAtomic<T> where T : NIOAtomicPrimitive

Atomic objects support a wide range of atomic operations:

  • Compare and swap

  • Add

  • Subtract

  • Exchange

  • Load current value

  • Store current value

Atomic primitives are useful when building constructs that need to communicate or cooperate across multiple threads. In the case of SwiftNIO this usually involves communicating across multiple event loops.

By necessity, all atomic values are references: after all, it makes no sense to talk about managing an atomic value when each time it’s modified the thread that modified it gets a local copy!