NIOLoopBound

NIOLoopBound is an always-Sendable, value-typed container allowing you access to value if and only if you are accessing it on the right EventLoop.

NIOLoopBound.swift:27
struct NIOLoopBound<Value>

NIOLoopBound is useful to transport a value of a non-Sendable type that needs to go from one place in your code to another where you (but not the compiler) know is on one and the same EventLoop. Usually this involves @Sendable closures. This type is safe because it verifies (using preconditionInEventLoop(file:line:)) that this is actually true.

A NIOLoopBound can only be constructed, read from or written to when you are provably (through preconditionInEventLoop(file:line:)) on the EventLoop associated with the NIOLoopBound. Accessing or constructing it from any other place will crash your program with a precondition as it would be undefined behaviour to do so.